`@MockKExtension.CheckUnnecessaryStub` does not work with `@MockkBean`
DasOhmoff opened this issue ยท 1 comments
DasOhmoff commented
Hello ๐, thank you for this nice plugin!
Mockk has the very usefull @MockKExtension.CheckUnnecessaryStub annotation, which automatically makes sure that no unnecessary stubbing of mocked objects was done within the tests. This is extremely usefull because:
- it keeps the code clean and tidy, removing unnecessary stubs
- it verifies ones assumptions, because all stubbed methods are expected to be called, otherwise ones assumptions were wrong, and probably some production code behaves not as expected
- it minimizes the need to use the
verify
block. If I stub a method and mockk makes sure that all stubbed methods got called, then I don't need to manually add theverify
block anymore in order to make sure that the method got called
These are the things that I thought about right now, but there are probably other benefits as well.
Unfortunatelly, this feature does not work with springmockk
. This is the code I tried it with:
@MockKExtension.CheckUnnecessaryStub
@ExtendWith(SpringExtension::class)
class SampleClassTest {
@MockkBean private lateinit var repo: SampleRepository
@Test
fun `test repo`() {
// No unnecessary stubbing reported.
every { repo.save(any()) } returns mockk()
// Only reported if manually checking via following line:
// checkUnnecessaryStub(repo)
}
}
It would be great to make it work with springmockk
too.
Thanks a lot :)
DasOhmoff commented
Hello, I still have this issue, any solutions to this yet?