Skip to content
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

Closed
daniel-frak opened this issue Jul 24, 2024 · 6 comments

Comments

@daniel-frak
Copy link

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().

@hcoles
Copy link
Owner

hcoles commented Jul 24, 2024

Which test framework are you using (JUnit 3/4/5, testng etc)

@daniel-frak
Copy link
Author

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.

@hcoles
Copy link
Owner

hcoles commented Jul 24, 2024

If you could put together a minimal project that replicates the issue, that would be helpful.

@daniel-frak
Copy link
Author

I whipped up a quick minimal repro:
https://github.com/daniel-frak/pitest-mockito-stubbing-issue-example

@hcoles
Copy link
Owner

hcoles commented Jul 29, 2024

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.

@hcoles
Copy link
Owner

hcoles commented Aug 9, 2024

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.

@hcoles hcoles closed this as completed Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants