mockito-scala icon indicating copy to clipboard operation
mockito-scala copied to clipboard

Strictness warn fails tests

Open mbbush opened this issue 3 years ago • 3 comments

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.

mbbush avatar Dec 19 '20 07:12 mbbush

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

ultrasecreth avatar Dec 19 '20 10:12 ultrasecreth

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.

mbbush avatar Dec 20 '20 05:12 mbbush

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

ultrasecreth avatar Dec 23 '20 20:12 ultrasecreth