New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to verify when spying on kotlin class #1851
Comments
@MFAshby You have to use Sry for not getting back to you on the original issue. Totally forgot. |
This works: open class SomeClass {
fun doThing1() {
doThing2()
}
open fun doThing2() {
println("Hey")
}
} public class SpyingProblemTest {
private SomeClass underTest = spy(new SomeClass());
@Test
public void cantVerifySpies() {
// WHEN
underTest.doThing1();
// THEN
verify(underTest, times(1)).doThing2();
}
@Test
public void cantVerifySpies2() {
// WHEN
underTest.doThing2();
// THEN
verify(underTest, times(1)).doThing2();
}
} |
Maybe change your dependency on Replace
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a test class with 2 tests (written in java). The tests are trying to verify the behaviour of the subject (written in kotlin) by spying on it.
Expected behaviour:
tests pass because the expected method call is made.
Actual behaviour:
The first test passes, and the second (identical) test receives an UnfinishedVerificationException
Compilable example here:
https://github.com/MFAshby/spying-problem-sample
Problematic code:
SomeClass.kt:
SpyingProblemTest.java:
Test output:
I originally logged this with mockito-kotlin but I subsequently reproduced the issue without that library, so I think the problem is in mockito.
Interesting version numbers:
The text was updated successfully, but these errors were encountered: