Tuesday, September 23, 2008

Mockito matchers

Configuration: Mockito 1.5, TestNG 5.8 jdk15, maven-surefire 2.4.2
Don't use mockito matchers (anyInt, anyString, ...) to 'mock' arguments for non-mocked/stubbed method calls. Using matchers this way can cause unpredictable test failures, as the state of matchers is being tracked statically (simpliest explanation I could come up with without digging into source). You might get an InvalidUseOfMatchersException in a test case different to the one matchers were used in.

No comments: