-
Notifications
You must be signed in to change notification settings - Fork 358
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
Pitest seems to ignore or never trigger Mockito's UnnecessaryStubbingException #1336
Comments
Which test framework are you using (JUnit 3/4/5, testng etc) |
I'm using Junit 5. I'm unsure of what other information could be useful, so let me know if I can provide any more info. |
If you could put together a minimal project that replicates the issue, that would be helpful. |
I whipped up a quick minimal repro: |
Been having a look at this, but not made much progress. It seems that the unnecessary stubbing check never triggers when running against a mutant (the tests fail correctly when run through pitest if the mutant is present when the test is first run). Unless I've missed something, this will require some digging into the internals of mockito. |
Hi @daniel-frak, Finally got chance to take a closer look at this today. After a bit of debugging I confirmed that stubbing exception are propagating as they should do. The actual issue is the usual difficultly understanding exactly what bytecode mutations look like when translated back to source, which tripped us both up. The mutation "removed conditional - replaced equality check with false" Mutates this private boolean conditionOneNotMet(TestObject2 testObject2) {
return !condition1Checker.checkCondition1(testObject2);
} To private boolean conditionOneNotMet(TestObject2 testObject2) {
condition1Checker.checkCondition1(testObject2);
return false;
} Retaining the method call. If you recreate this mutant manually, you'll see that all tests pass. So I believe everything is working as expected. |
Given a mutation, if a test mutated this way would normally fail with
org.mockito.exceptions.misusing.UnnecessaryStubbingException
, Pitest will report it as having survived.It seems that Pitest never triggers Mockito's UnnecessaryStubbing checks.
I have encountered this issue more than once, where I was doing the same modifications as Pitest but getting different results, before realising that Pitest behaves as if all stubbings were
lenient()
.The text was updated successfully, but these errors were encountered: