mockito-scala
mockito-scala copied to clipboard
Strictness warn fails tests
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.
So you mean lenient
works as expected but warn
behaves the same as strict
?
Mind posting a small snippet to reproduce?
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.
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