@Mock members of test classes shouldn't share state between tests and preferably be non-static


The problem

Making a @Mock instance static will share the state across tests and can make them order dependent and/or unclear to reader/maintainer. Removing static, will ensure fresh mock instances are used for each tests.

Additionally, if the @Mock instance is marked as static to make it serializable, there is a cleaner way to do it : and–


Suppress false positives by adding the suppression annotation @SuppressWarnings("StaticMockMember") to the enclosing element.