pitest
pitest copied to clipboard
Support of Mockk as Mocking Framework for Kotlin
I have tried to run a simple test-case with Mockk https://mockk.io/, but it doesn't work.
class PitMockkDepUseCaseTest {
@Test
fun test() {
mockkConstructor(PitProvider::class)
every { anyConstructed<PitProvider>().provideNumber() } returns 4
Assertions.assertThat(PitDepUseCase().execute(1)).isEqualTo(5)
}
}
The same test with Mockito worked.
class PitMockitoDepUseCaseTest {
@Test
fun test() {
mock<PitProvider> {
on {
provideNumber()
} doReturn (4)
}
Assertions.assertThat(PitDepUseCase().execute(1)).isEqualTo(5)
}
}
I get a sequence of exception when I run the gradle tasks.
Caused by: java.lang.ClassNotFoundException: io.mockk.proxy.MockKAgentFactory
Is there a way to support Mockk ?
After debugging, I added the following dependencies to make it running :
testImplementation "io.mockk:mockk-agent-api:1.10.0"
testImplementation "io.mockk:mockk-agent-jvm:1.10.0"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
But I think this should be easy as it is with Mockito and others.