mardi 17 septembre 2019

No definition found for qualifier: How to solve Kotlin reflection is not available when creating modules with Koin test?

I'm trying to create a simple white-box test with Koin. After setting qualifier to pass a mock as parameter to an instance (or supposedly what I want to do) I'm receiving an error which says:

org.koin.core.error.NoBeanDefFoundException: No definition found for qualifier='null' & class='class com.stonetree.imagebucket.main.repository.GalleryRepositoryImpl (Kotlin reflection is not available)'

This is my test class:

class GalleryRepositoryTest: AutoCloseKoinTest() {

    private val module = module {
        named("repository").apply {
            single<GalleryRepository>(this) { GalleryRepositoryImpl() }
            single { GalleryViewModel(get(this.javaClass)) }
        }
    }

    private val repository: GalleryRepositoryImpl by inject()
    private val vm: GalleryViewModel by inject()

    @Before
    fun setup() {
        startKoin { loadKoinModules(module) }
        declareMock<GalleryRepositoryImpl>()
    }

    @Test
    fun uploadImage_withEmptyUri_shouldDoNothing() {
        vm.delete("")
        verify(repository).delete("")
    }
}

I also tried a similar approach with Robolectric runner, but after creating the module in Application file, my mock wouldn't be invoked using verify(repository).delete("").

How can I manage to solve this problem and move forward with this simple test?





Aucun commentaire:

Enregistrer un commentaire