Hey all! I’m having an strange issue while using J...
# koin
s
Hey all! I’m having an strange issue while using JUnit5. I have a test… that worked before but now it’s not working anymore and I didn’t change anything on the modules or the test or even the class. The error is:
Copy code
JUnit Jupiter:Hello repository tests:check repository response includes "Server"()
    MethodSource [className = 'net.sierisimo.hello.HelloRepositoryTest', methodName = 'check repository response includes "Server"', methodParameterTypes = '']
    => org.koin.error.AlreadyStartedException: Koin is already started. Run startKoin only once or use loadKoinModules
       org.koin.standalone.StandAloneContext.startKoin(StandAloneContext.kt:124)
       org.koin.standalone.StandAloneContext.startKoin$default(StandAloneContext.kt:121)
       net.sierisimo.hello.HelloRepositoryTest.before(HelloRepositoryTest.kt:21)
       sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       java.lang.reflect.Method.invoke(Method.java:498)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:513)
       org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
       org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeMethodInExtensionContext(ClassTestDescriptor.java:302)
And the class itself is:
Copy code
@DisplayName("Hello repository tests")
internal class HelloRepositoryTest : KoinTest {
    private val helloRepository: HelloRepository by inject()

    @BeforeEach
    fun before() {
        startKoin(listOf(helloModule))
    }

    @AfterEach
    fun after() {
        closeKoin()
    }

    @Test
    fun `check the repository returns a non empty String`() {
        val value = helloRepository.getHello()
        assertTrue(value.isNotEmpty(), "String response should be more than 1 character")
    }

    @Test
    fun `check repository response includes "Server"`() {
        assert(helloRepository.getHello()).contains("Server").isNotEmpty()
    }
}