Hi I can't find an exmaple of MockProvider.registe...
# koin
p
Hi I can't find an exmaple of MockProvider.register in kotlin multiplatform for unit tests in commonTest and mokery with useJunit. How to use MockProvider ?
a
it's mainly JVM Junit based. You'll find it in koin-test-junit4
p
I'm using junit5 but no equivalent to MockProvider like in mockk library :
Copy code
@get:Rule
val mockProvider = MockProviderRule.create { clazz ->
    // Your way to build a Mock here
    mockkClass(clazz)
}
if works if I do it for example
Copy code
class MyUseCaseTest: KoinTest {
    
    private lateinit var myUseCase: MyUseCase
    private lateinit var fooInterface: FooInterface
    
    @BeforeTest
    fun setUp() {

        MockProvider.register {
           mock<FooInterface>()
        }
        startKoin {
            modules(myModule)
            allowOverride(true)
        }
        fooInterface = declareMock<FooInterface> {
            everySuspend { myMethod(any()) } returns Unit 
        }
        myUseCase = get()
    }

    @Test
    fun myTest() = runTest {
        val text = "Test text"
        shareTextUseCase(text)
        verifySuspend {
            fooInterface.myMethod(text)
        }
    }

  fun tearDown() {
    stopKoin()
  }
}
a
yes, surely missing something in the Junit5 part 👍
p
in fact it's in mokery there is not equivalent like rule in mockk (I've no find solution to make mock<*>, need to put generic name)