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

Strictness warn fails tests #328

Open
mbbush opened this issue Dec 19, 2020 · 3 comments
Open

Strictness warn fails tests #328

mbbush opened this issue Dec 19, 2020 · 3 comments

Comments

@mbbush
Copy link

mbbush commented Dec 19, 2020

When I run my test suite that has many tests with unexpected invocations, unused stubbing, or both, I get the same number of failures regardless of whether I set the Strictness of the session to Warn or StrictStubs.

I stepped through the code, and I think the problem is that MockitoScalaSessionListener#reportIssues is not checking the strictness. When the strictness is lenient, all the unexpected invocations have already been filtered out when listener.cleanLenientStubs was called in MockitoScalaSession#finishMocking, so the library behaves as expected in that case. But when the strictness is either Warn or Strict, they don't get filtered out, and they get reported as reasons to fail the test. For Strict this is good, but not for Warn.

I was a little confused by this, because it seems like the UniversalTestListener is already handling reporting of unexpected invocations, in a way that either does nothing, warns, or fails the test, depending on strictness. I assume there's some reason for the apparent duplication in the MockitoScalaSessionListener, but I'm not familiar enough with the architecture of the library to see why.

I'm just getting started with upgrading an existing scala project from using a 2-year-old version of java mockito to the latest version of scala-mockito, so I'm still very new to these concepts.

@ultrasecreth
Copy link
Member

So you mean lenient works as expected but warn behaves the same as strict?
Mind posting a small snippet to reproduce?

@mbbush
Copy link
Author

mbbush commented Dec 20, 2020

Yes, that's what I mean, at least as far as whether the tests pass or fail. I haven't exhaustively compared the output to know if there are differences in what is printed to the console or not.

@ultrasecreth
Copy link
Member

This could be due to the fact that mockito-scala is even stricter than mockito-core, so I may have missed something there, if you could please point me to one or two scenarios where it fails for you I can take a look and get it sorted

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