BeanInstanceCreationException: Can't create definition for Single











up vote
0
down vote

favorite












I'm trying to run instrumented tests under androidTest folder using Koin creator's example. Each test passes if I run them one by one. But when I run them all at once only the first passes. The rest is failed with: BeanInstanceCreationException: Can't create definition for 'Single [name='MovieDatabase',.... Here's my tests:



class MovieDatabaseTest: AutoCloseKoinTest() {

@get:Rule val instantExecutorRule = InstantTaskExecutorRule()
private val movieDatabase: MovieDatabase by inject()
private val movieDAO: DetailDao by inject()

private val testModule = module {
single(override = true) {
Room.inMemoryDatabaseBuilder(androidContext (), MovieDatabase::class.java)
.allowMainThreadQueries()
.build()
}
}

@Before fun setUp() {
loadKoinModules(testModule)
}

@After fun tearDown() {
movieDatabase.close()
}

@Test
fun saveMovieTest() {
val observer = mock<Observer<Movie>>()
val date = Date()
val movie = buildMovie(1, dateUpdate = date)
val captor = ArgumentCaptor.forClass(Movie::class.java)

movieDAO.saveMovie(movie)
val movieLD = movieDAO.getMovie(1)
movieLD.observeForever(observer)

verify(observer).onChanged(captor.capture())
assertEquals(captor.value, buildMovie(1, dateUpdate = date))
}

@Test
fun likeTest() {
val movie = buildMovie(1)

movieDAO.saveMovie(movie)
movieDAO.like(1, true)
val movieLD = movieDAO.getMovie(1)
movieLD.observeForever {
assert(it.liked)
}
}

@Test
fun getMovieByDateTest() {
val dateUpdate = Date()
val queryDate = Date(System.currentTimeMillis() - 3600 * 1000)
val movie = buildMovie(1, dateUpdate = dateUpdate)
movieDAO.saveMovie(movie)

val savedMovie = movieDAO.getMovieByDate(1, queryDate)
assertNotNull(savedMovie)
}
}


Error stack trace:



    org.koin.error.BeanInstanceCreationException: Can't create definition for 'Single [name='MovieDatabase',class='us.kostenko.architecturecomponentstmdb.common.database.MovieDatabase']' due to error :
No compatible definition found. Check your module definition
org.koin.core.bean.BeanRegistry.checkedResult(BeanRegistry.kt:120)
org.koin.core.bean.BeanRegistry.retrieveDefinition(BeanRegistry.kt:87)
org.koin.core.instance.InstanceRegistry.findDefinition(InstanceRegistry.kt:125)
org.koin.core.instance.InstanceRegistry.access$findDefinition(InstanceRegistry.kt:39)
org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$1.invoke(InstanceRegistry.kt:91)
org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$1.invoke(InstanceRegistry.kt:39)
org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:90)
org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
org.koin.android.ext.koin.ContextExtKt.androidContext(ContextExt.kt:42)
us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$testModule$1$1.invoke(MovieDatabaseTest.kt:34)
us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$testModule$1$1.invoke(MovieDatabaseTest.kt:26)
org.koin.core.instance.holder.InstanceHolder$DefaultImpls.create(InstanceHolder.kt:17)
org.koin.core.instance.holder.SingleInstanceHolder.create(SingleInstanceHolder.kt:10)
org.koin.core.instance.holder.SingleInstanceHolder.get(SingleInstanceHolder.kt:19)
org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:53)
org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:138)
org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:39)
org.koin.core.stack.ResolutionStack.resolve(ResolutionStack.kt:44)
org.koin.core.instance.InstanceRegistry.resolveInstance(InstanceRegistry.kt:137)
org.koin.core.instance.InstanceRegistry.access$resolveInstance(InstanceRegistry.kt:39)
org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:98)
org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:39)
org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:97)
org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$$special$$inlined$inject$1.invoke(KoinComponent.kt:143)
kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.getMovieDatabase(Unknown Source:7)
us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.tearDown(MovieDatabaseTest.kt:45)
java.lang.reflect.Method.invoke(Native Method)
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:80)
org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
org.junit.rules.RunRules.evaluate(RunRules.java:20)
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
org.junit.runners.ParentRunner.run(ParentRunner.java:363)
org.junit.runners.Suite.runChild(Suite.java:128)
org.junit.runners.Suite.runChild(Suite.java:27)
org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
org.junit.runners.ParentRunner.run(ParentRunner.java:363)
org.junit.runner.JUnitCore.run(JUnitCore.java:137)
org.junit.runner.JUnitCore.run(JUnitCore.java:115)
androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)
at org.koin.core.instance.holder.InstanceHolder$DefaultImpls.create(InstanceHolder.kt:23)
at org.koin.core.instance.holder.SingleInstanceHolder.create(SingleInstanceHolder.kt:10)
at org.koin.core.instance.holder.SingleInstanceHolder.get(SingleInstanceHolder.kt:19)
at org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:53)
at org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:138)
at org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:39)
at org.koin.core.stack.ResolutionStack.resolve(ResolutionStack.kt:44)
at org.koin.core.instance.InstanceRegistry.resolveInstance(InstanceRegistry.kt:137)
at org.koin.core.instance.InstanceRegistry.access$resolveInstance(InstanceRegistry.kt:39)
at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:98)
at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:39)
at org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:97)
at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
at org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
at org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
at org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$$special$$inlined$inject$1.invoke(KoinComponent.kt:143)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.getMovieDatabase(Unknown Source:7)
at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.tearDown(MovieDatabaseTest.kt:45)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:80)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)


Here also my non-testing module definitions that I launch with startKoin(this, listOf(baseModule, movieDetailModule)) from my Application implementation:



    val baseModule = module {

factory<Coroutines> { AndroidCoroutines() }

single { Room.databaseBuilder(androidContext(), MovieDatabase::class.java, "movies-db")
.fallbackToDestructiveMigration().build() }

single { TmdbRetrofitBuilder(androidContext()).buildRetrofit() }
}

val movieDetailModule = module {

single { get<MovieDatabase>().detailDao() }

single<MovieWebService>{ get<Retrofit>().create(MovieWebService::class.java) }

single<MovieDetailRepository>{ MovieDetailRepositoryImpl(get(), get(), get()) }

viewModel { MovieDetailViewModel(get(), get()) }
}


It seems it has something to do with movieDatabase.close() line, but I can't figure out configuration that would work between tests.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm trying to run instrumented tests under androidTest folder using Koin creator's example. Each test passes if I run them one by one. But when I run them all at once only the first passes. The rest is failed with: BeanInstanceCreationException: Can't create definition for 'Single [name='MovieDatabase',.... Here's my tests:



    class MovieDatabaseTest: AutoCloseKoinTest() {

    @get:Rule val instantExecutorRule = InstantTaskExecutorRule()
    private val movieDatabase: MovieDatabase by inject()
    private val movieDAO: DetailDao by inject()

    private val testModule = module {
    single(override = true) {
    Room.inMemoryDatabaseBuilder(androidContext (), MovieDatabase::class.java)
    .allowMainThreadQueries()
    .build()
    }
    }

    @Before fun setUp() {
    loadKoinModules(testModule)
    }

    @After fun tearDown() {
    movieDatabase.close()
    }

    @Test
    fun saveMovieTest() {
    val observer = mock<Observer<Movie>>()
    val date = Date()
    val movie = buildMovie(1, dateUpdate = date)
    val captor = ArgumentCaptor.forClass(Movie::class.java)

    movieDAO.saveMovie(movie)
    val movieLD = movieDAO.getMovie(1)
    movieLD.observeForever(observer)

    verify(observer).onChanged(captor.capture())
    assertEquals(captor.value, buildMovie(1, dateUpdate = date))
    }

    @Test
    fun likeTest() {
    val movie = buildMovie(1)

    movieDAO.saveMovie(movie)
    movieDAO.like(1, true)
    val movieLD = movieDAO.getMovie(1)
    movieLD.observeForever {
    assert(it.liked)
    }
    }

    @Test
    fun getMovieByDateTest() {
    val dateUpdate = Date()
    val queryDate = Date(System.currentTimeMillis() - 3600 * 1000)
    val movie = buildMovie(1, dateUpdate = dateUpdate)
    movieDAO.saveMovie(movie)

    val savedMovie = movieDAO.getMovieByDate(1, queryDate)
    assertNotNull(savedMovie)
    }
    }


    Error stack trace:



        org.koin.error.BeanInstanceCreationException: Can't create definition for 'Single [name='MovieDatabase',class='us.kostenko.architecturecomponentstmdb.common.database.MovieDatabase']' due to error :
    No compatible definition found. Check your module definition
    org.koin.core.bean.BeanRegistry.checkedResult(BeanRegistry.kt:120)
    org.koin.core.bean.BeanRegistry.retrieveDefinition(BeanRegistry.kt:87)
    org.koin.core.instance.InstanceRegistry.findDefinition(InstanceRegistry.kt:125)
    org.koin.core.instance.InstanceRegistry.access$findDefinition(InstanceRegistry.kt:39)
    org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$1.invoke(InstanceRegistry.kt:91)
    org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$1.invoke(InstanceRegistry.kt:39)
    org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
    org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:90)
    org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
    org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
    org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
    org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
    org.koin.android.ext.koin.ContextExtKt.androidContext(ContextExt.kt:42)
    us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$testModule$1$1.invoke(MovieDatabaseTest.kt:34)
    us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$testModule$1$1.invoke(MovieDatabaseTest.kt:26)
    org.koin.core.instance.holder.InstanceHolder$DefaultImpls.create(InstanceHolder.kt:17)
    org.koin.core.instance.holder.SingleInstanceHolder.create(SingleInstanceHolder.kt:10)
    org.koin.core.instance.holder.SingleInstanceHolder.get(SingleInstanceHolder.kt:19)
    org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:53)
    org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:138)
    org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:39)
    org.koin.core.stack.ResolutionStack.resolve(ResolutionStack.kt:44)
    org.koin.core.instance.InstanceRegistry.resolveInstance(InstanceRegistry.kt:137)
    org.koin.core.instance.InstanceRegistry.access$resolveInstance(InstanceRegistry.kt:39)
    org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:98)
    org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:39)
    org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
    org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:97)
    org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
    org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
    org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
    org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
    us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$$special$$inlined$inject$1.invoke(KoinComponent.kt:143)
    kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.getMovieDatabase(Unknown Source:7)
    us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.tearDown(MovieDatabaseTest.kt:45)
    java.lang.reflect.Method.invoke(Native Method)
    org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:80)
    org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
    org.junit.rules.RunRules.evaluate(RunRules.java:20)
    org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    org.junit.runners.Suite.runChild(Suite.java:128)
    org.junit.runners.Suite.runChild(Suite.java:27)
    org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
    androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
    android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)
    at org.koin.core.instance.holder.InstanceHolder$DefaultImpls.create(InstanceHolder.kt:23)
    at org.koin.core.instance.holder.SingleInstanceHolder.create(SingleInstanceHolder.kt:10)
    at org.koin.core.instance.holder.SingleInstanceHolder.get(SingleInstanceHolder.kt:19)
    at org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:53)
    at org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:138)
    at org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:39)
    at org.koin.core.stack.ResolutionStack.resolve(ResolutionStack.kt:44)
    at org.koin.core.instance.InstanceRegistry.resolveInstance(InstanceRegistry.kt:137)
    at org.koin.core.instance.InstanceRegistry.access$resolveInstance(InstanceRegistry.kt:39)
    at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:98)
    at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:39)
    at org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
    at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:97)
    at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
    at org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
    at org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
    at org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
    at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$$special$$inlined$inject$1.invoke(KoinComponent.kt:143)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.getMovieDatabase(Unknown Source:7)
    at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.tearDown(MovieDatabaseTest.kt:45)
    at java.lang.reflect.Method.invoke(Native Method)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:80)
    at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
    at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)


    Here also my non-testing module definitions that I launch with startKoin(this, listOf(baseModule, movieDetailModule)) from my Application implementation:



        val baseModule = module {

    factory<Coroutines> { AndroidCoroutines() }

    single { Room.databaseBuilder(androidContext(), MovieDatabase::class.java, "movies-db")
    .fallbackToDestructiveMigration().build() }

    single { TmdbRetrofitBuilder(androidContext()).buildRetrofit() }
    }

    val movieDetailModule = module {

    single { get<MovieDatabase>().detailDao() }

    single<MovieWebService>{ get<Retrofit>().create(MovieWebService::class.java) }

    single<MovieDetailRepository>{ MovieDetailRepositoryImpl(get(), get(), get()) }

    viewModel { MovieDetailViewModel(get(), get()) }
    }


    It seems it has something to do with movieDatabase.close() line, but I can't figure out configuration that would work between tests.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to run instrumented tests under androidTest folder using Koin creator's example. Each test passes if I run them one by one. But when I run them all at once only the first passes. The rest is failed with: BeanInstanceCreationException: Can't create definition for 'Single [name='MovieDatabase',.... Here's my tests:



      class MovieDatabaseTest: AutoCloseKoinTest() {

      @get:Rule val instantExecutorRule = InstantTaskExecutorRule()
      private val movieDatabase: MovieDatabase by inject()
      private val movieDAO: DetailDao by inject()

      private val testModule = module {
      single(override = true) {
      Room.inMemoryDatabaseBuilder(androidContext (), MovieDatabase::class.java)
      .allowMainThreadQueries()
      .build()
      }
      }

      @Before fun setUp() {
      loadKoinModules(testModule)
      }

      @After fun tearDown() {
      movieDatabase.close()
      }

      @Test
      fun saveMovieTest() {
      val observer = mock<Observer<Movie>>()
      val date = Date()
      val movie = buildMovie(1, dateUpdate = date)
      val captor = ArgumentCaptor.forClass(Movie::class.java)

      movieDAO.saveMovie(movie)
      val movieLD = movieDAO.getMovie(1)
      movieLD.observeForever(observer)

      verify(observer).onChanged(captor.capture())
      assertEquals(captor.value, buildMovie(1, dateUpdate = date))
      }

      @Test
      fun likeTest() {
      val movie = buildMovie(1)

      movieDAO.saveMovie(movie)
      movieDAO.like(1, true)
      val movieLD = movieDAO.getMovie(1)
      movieLD.observeForever {
      assert(it.liked)
      }
      }

      @Test
      fun getMovieByDateTest() {
      val dateUpdate = Date()
      val queryDate = Date(System.currentTimeMillis() - 3600 * 1000)
      val movie = buildMovie(1, dateUpdate = dateUpdate)
      movieDAO.saveMovie(movie)

      val savedMovie = movieDAO.getMovieByDate(1, queryDate)
      assertNotNull(savedMovie)
      }
      }


      Error stack trace:



          org.koin.error.BeanInstanceCreationException: Can't create definition for 'Single [name='MovieDatabase',class='us.kostenko.architecturecomponentstmdb.common.database.MovieDatabase']' due to error :
      No compatible definition found. Check your module definition
      org.koin.core.bean.BeanRegistry.checkedResult(BeanRegistry.kt:120)
      org.koin.core.bean.BeanRegistry.retrieveDefinition(BeanRegistry.kt:87)
      org.koin.core.instance.InstanceRegistry.findDefinition(InstanceRegistry.kt:125)
      org.koin.core.instance.InstanceRegistry.access$findDefinition(InstanceRegistry.kt:39)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$1.invoke(InstanceRegistry.kt:91)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$1.invoke(InstanceRegistry.kt:39)
      org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:90)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
      org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
      org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
      org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
      org.koin.android.ext.koin.ContextExtKt.androidContext(ContextExt.kt:42)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$testModule$1$1.invoke(MovieDatabaseTest.kt:34)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$testModule$1$1.invoke(MovieDatabaseTest.kt:26)
      org.koin.core.instance.holder.InstanceHolder$DefaultImpls.create(InstanceHolder.kt:17)
      org.koin.core.instance.holder.SingleInstanceHolder.create(SingleInstanceHolder.kt:10)
      org.koin.core.instance.holder.SingleInstanceHolder.get(SingleInstanceHolder.kt:19)
      org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:53)
      org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:138)
      org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:39)
      org.koin.core.stack.ResolutionStack.resolve(ResolutionStack.kt:44)
      org.koin.core.instance.InstanceRegistry.resolveInstance(InstanceRegistry.kt:137)
      org.koin.core.instance.InstanceRegistry.access$resolveInstance(InstanceRegistry.kt:39)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:98)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:39)
      org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:97)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
      org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
      org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
      org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$$special$$inlined$inject$1.invoke(KoinComponent.kt:143)
      kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.getMovieDatabase(Unknown Source:7)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.tearDown(MovieDatabaseTest.kt:45)
      java.lang.reflect.Method.invoke(Native Method)
      org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:80)
      org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
      org.junit.rules.RunRules.evaluate(RunRules.java:20)
      org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      org.junit.runners.Suite.runChild(Suite.java:128)
      org.junit.runners.Suite.runChild(Suite.java:27)
      org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      org.junit.runner.JUnitCore.run(JUnitCore.java:115)
      androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
      androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
      android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)
      at org.koin.core.instance.holder.InstanceHolder$DefaultImpls.create(InstanceHolder.kt:23)
      at org.koin.core.instance.holder.SingleInstanceHolder.create(SingleInstanceHolder.kt:10)
      at org.koin.core.instance.holder.SingleInstanceHolder.get(SingleInstanceHolder.kt:19)
      at org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:53)
      at org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:138)
      at org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:39)
      at org.koin.core.stack.ResolutionStack.resolve(ResolutionStack.kt:44)
      at org.koin.core.instance.InstanceRegistry.resolveInstance(InstanceRegistry.kt:137)
      at org.koin.core.instance.InstanceRegistry.access$resolveInstance(InstanceRegistry.kt:39)
      at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:98)
      at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:39)
      at org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
      at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:97)
      at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
      at org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
      at org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
      at org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
      at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$$special$$inlined$inject$1.invoke(KoinComponent.kt:143)
      at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
      at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.getMovieDatabase(Unknown Source:7)
      at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.tearDown(MovieDatabaseTest.kt:45)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:80)
      at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
      at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runners.Suite.runChild(Suite.java:128)
      at org.junit.runners.Suite.runChild(Suite.java:27)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
      at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
      at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
      at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)


      Here also my non-testing module definitions that I launch with startKoin(this, listOf(baseModule, movieDetailModule)) from my Application implementation:



          val baseModule = module {

      factory<Coroutines> { AndroidCoroutines() }

      single { Room.databaseBuilder(androidContext(), MovieDatabase::class.java, "movies-db")
      .fallbackToDestructiveMigration().build() }

      single { TmdbRetrofitBuilder(androidContext()).buildRetrofit() }
      }

      val movieDetailModule = module {

      single { get<MovieDatabase>().detailDao() }

      single<MovieWebService>{ get<Retrofit>().create(MovieWebService::class.java) }

      single<MovieDetailRepository>{ MovieDetailRepositoryImpl(get(), get(), get()) }

      viewModel { MovieDetailViewModel(get(), get()) }
      }


      It seems it has something to do with movieDatabase.close() line, but I can't figure out configuration that would work between tests.










      share|improve this question















      I'm trying to run instrumented tests under androidTest folder using Koin creator's example. Each test passes if I run them one by one. But when I run them all at once only the first passes. The rest is failed with: BeanInstanceCreationException: Can't create definition for 'Single [name='MovieDatabase',.... Here's my tests:



      class MovieDatabaseTest: AutoCloseKoinTest() {

      @get:Rule val instantExecutorRule = InstantTaskExecutorRule()
      private val movieDatabase: MovieDatabase by inject()
      private val movieDAO: DetailDao by inject()

      private val testModule = module {
      single(override = true) {
      Room.inMemoryDatabaseBuilder(androidContext (), MovieDatabase::class.java)
      .allowMainThreadQueries()
      .build()
      }
      }

      @Before fun setUp() {
      loadKoinModules(testModule)
      }

      @After fun tearDown() {
      movieDatabase.close()
      }

      @Test
      fun saveMovieTest() {
      val observer = mock<Observer<Movie>>()
      val date = Date()
      val movie = buildMovie(1, dateUpdate = date)
      val captor = ArgumentCaptor.forClass(Movie::class.java)

      movieDAO.saveMovie(movie)
      val movieLD = movieDAO.getMovie(1)
      movieLD.observeForever(observer)

      verify(observer).onChanged(captor.capture())
      assertEquals(captor.value, buildMovie(1, dateUpdate = date))
      }

      @Test
      fun likeTest() {
      val movie = buildMovie(1)

      movieDAO.saveMovie(movie)
      movieDAO.like(1, true)
      val movieLD = movieDAO.getMovie(1)
      movieLD.observeForever {
      assert(it.liked)
      }
      }

      @Test
      fun getMovieByDateTest() {
      val dateUpdate = Date()
      val queryDate = Date(System.currentTimeMillis() - 3600 * 1000)
      val movie = buildMovie(1, dateUpdate = dateUpdate)
      movieDAO.saveMovie(movie)

      val savedMovie = movieDAO.getMovieByDate(1, queryDate)
      assertNotNull(savedMovie)
      }
      }


      Error stack trace:



          org.koin.error.BeanInstanceCreationException: Can't create definition for 'Single [name='MovieDatabase',class='us.kostenko.architecturecomponentstmdb.common.database.MovieDatabase']' due to error :
      No compatible definition found. Check your module definition
      org.koin.core.bean.BeanRegistry.checkedResult(BeanRegistry.kt:120)
      org.koin.core.bean.BeanRegistry.retrieveDefinition(BeanRegistry.kt:87)
      org.koin.core.instance.InstanceRegistry.findDefinition(InstanceRegistry.kt:125)
      org.koin.core.instance.InstanceRegistry.access$findDefinition(InstanceRegistry.kt:39)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$1.invoke(InstanceRegistry.kt:91)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$1.invoke(InstanceRegistry.kt:39)
      org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:90)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
      org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
      org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
      org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
      org.koin.android.ext.koin.ContextExtKt.androidContext(ContextExt.kt:42)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$testModule$1$1.invoke(MovieDatabaseTest.kt:34)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$testModule$1$1.invoke(MovieDatabaseTest.kt:26)
      org.koin.core.instance.holder.InstanceHolder$DefaultImpls.create(InstanceHolder.kt:17)
      org.koin.core.instance.holder.SingleInstanceHolder.create(SingleInstanceHolder.kt:10)
      org.koin.core.instance.holder.SingleInstanceHolder.get(SingleInstanceHolder.kt:19)
      org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:53)
      org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:138)
      org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:39)
      org.koin.core.stack.ResolutionStack.resolve(ResolutionStack.kt:44)
      org.koin.core.instance.InstanceRegistry.resolveInstance(InstanceRegistry.kt:137)
      org.koin.core.instance.InstanceRegistry.access$resolveInstance(InstanceRegistry.kt:39)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:98)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:39)
      org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:97)
      org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
      org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
      org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
      org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$$special$$inlined$inject$1.invoke(KoinComponent.kt:143)
      kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.getMovieDatabase(Unknown Source:7)
      us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.tearDown(MovieDatabaseTest.kt:45)
      java.lang.reflect.Method.invoke(Native Method)
      org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:80)
      org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
      org.junit.rules.RunRules.evaluate(RunRules.java:20)
      org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      org.junit.runners.Suite.runChild(Suite.java:128)
      org.junit.runners.Suite.runChild(Suite.java:27)
      org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      org.junit.runner.JUnitCore.run(JUnitCore.java:115)
      androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
      androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
      android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)
      at org.koin.core.instance.holder.InstanceHolder$DefaultImpls.create(InstanceHolder.kt:23)
      at org.koin.core.instance.holder.SingleInstanceHolder.create(SingleInstanceHolder.kt:10)
      at org.koin.core.instance.holder.SingleInstanceHolder.get(SingleInstanceHolder.kt:19)
      at org.koin.core.instance.InstanceFactory.retrieveInstance(InstanceFactory.kt:53)
      at org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:138)
      at org.koin.core.instance.InstanceRegistry$resolveInstance$1.invoke(InstanceRegistry.kt:39)
      at org.koin.core.stack.ResolutionStack.resolve(ResolutionStack.kt:44)
      at org.koin.core.instance.InstanceRegistry.resolveInstance(InstanceRegistry.kt:137)
      at org.koin.core.instance.InstanceRegistry.access$resolveInstance(InstanceRegistry.kt:39)
      at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:98)
      at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1$2.invoke(InstanceRegistry.kt:39)
      at org.koin.core.time.DurationKt.logDuration(Duration.kt:11)
      at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:97)
      at org.koin.core.instance.InstanceRegistry$proceedResolution$$inlined$synchronized$lambda$1.invoke(InstanceRegistry.kt:39)
      at org.koin.core.time.DurationKt.measureDuration(Duration.kt:19)
      at org.koin.core.instance.InstanceRegistry.proceedResolution(InstanceRegistry.kt:87)
      at org.koin.core.instance.InstanceRegistry.resolve(InstanceRegistry.kt:61)
      at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest$$special$$inlined$inject$1.invoke(KoinComponent.kt:143)
      at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
      at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.getMovieDatabase(Unknown Source:7)
      at us.kostenko.architecturecomponentstmdb.details.repository.MovieDatabaseTest.tearDown(MovieDatabaseTest.kt:45)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:80)
      at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
      at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runners.Suite.runChild(Suite.java:128)
      at org.junit.runners.Suite.runChild(Suite.java:27)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
      at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
      at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
      at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)


      Here also my non-testing module definitions that I launch with startKoin(this, listOf(baseModule, movieDetailModule)) from my Application implementation:



          val baseModule = module {

      factory<Coroutines> { AndroidCoroutines() }

      single { Room.databaseBuilder(androidContext(), MovieDatabase::class.java, "movies-db")
      .fallbackToDestructiveMigration().build() }

      single { TmdbRetrofitBuilder(androidContext()).buildRetrofit() }
      }

      val movieDetailModule = module {

      single { get<MovieDatabase>().detailDao() }

      single<MovieWebService>{ get<Retrofit>().create(MovieWebService::class.java) }

      single<MovieDetailRepository>{ MovieDetailRepositoryImpl(get(), get(), get()) }

      viewModel { MovieDetailViewModel(get(), get()) }
      }


      It seems it has something to do with movieDatabase.close() line, but I can't figure out configuration that would work between tests.







      android koin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      Sergey Glotov

      16.4k117288




      16.4k117288










      asked 2 days ago









      AlexKost

      5271518




      5271518





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373136%2fbeaninstancecreationexception-cant-create-definition-for-single%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373136%2fbeaninstancecreationexception-cant-create-definition-for-single%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]