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

Unused stubbings are not reported when filters are used #3077

Closed
C0urante opened this issue Aug 4, 2023 · 2 comments · Fixed by #3078
Closed

Unused stubbings are not reported when filters are used #3077

C0urante opened this issue Aug 4, 2023 · 2 comments · Fixed by #3078

Comments

@C0urante
Copy link
Contributor

C0urante commented Aug 4, 2023

Unused stubbings are not reported when a filter is used during the test run. This is documented clearly in the StrictRunner class:

// only report when:
// 1. if all tests from given test have ran (filter requested is false)
//   Otherwise we would report unnecessary stubs even if the user runs just single test
// from the class
// 2. tests are successful (we don't want to add an extra failure on top of any existing
// failure, to avoid confusion)

Only reporting unused stubbings when all tests are run is reasonable. However, the logic for detecting this case is a little too coarse-grained, since even no-op filters end up disabling the reporting of unused stubbings. This can be troublesome when, for example, JUnit categories are used to distinguish between unit and integration tests.

It'd be nice if we could detect when filters actually prevent one or more tests from being run, and only skip reporting unused stubbings in those cases.

Created based off of gradle/gradle#10694, specifically this comment.

This affects a project currently using Mockito version 4.11.0, but I've just verified that it also affects version 5.2.0.

@C0urante
Copy link
Contributor Author

C0urante commented Aug 4, 2023

I've held off on providing a reproducible example as I hope the description is clear enough; can give it a shot if more detail is required, though.

C0urante added a commit to C0urante/mockito that referenced this issue Aug 4, 2023
C0urante added a commit to C0urante/mockito that referenced this issue Aug 4, 2023
@C0urante
Copy link
Contributor Author

C0urante commented Aug 4, 2023

Added a unit test case to #3078 that gives a decent picture of what this describes, but without some of the outer context (e.g., Gradle and JUnit exclusion categories) that helps demonstrate the impact of the current behavior.

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

Successfully merging a pull request may close this issue.

1 participant