mockito: Mockito JUnit Jupiter extension does not correctly support parallel test execution

Sorry for not being able to provide the required information, but we just noticed that the MockitoExtension (mockito-junit-jupiter 2.24.5) leads to spurious test failures (e.g. due to calls to mocks not being recorded) when using “junit.jupiter.execution.parallel.enabled=true” with surefire. Prior we used our much simpler MockitoExtension which works fine in the same situation:

public class MockitoExtension implements Extension, TestInstancePostProcessor, AfterEachCallback {
   @Override
   public void postProcessTestInstance(Object testInstance, ExtensionContext context) {
      MockitoAnnotations.initMocks(testInstance);
   }

   @Override
   public void afterEach(ExtensionContext extensionContext) throws Exception {
      Mockito.validateMockitoUsage();
   }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 25 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I will publish a release today

I updated https://github.com/SchulteMarkus/mockito.bug1630 - seems to work without problems using Mockito v.3.1.0, thanks a lot! I will delete https://github.com/SchulteMarkus/mockito.bug1630 within a few weeks.

To be a bit more specific, WantedButNotInvoked exceptions are thrown by verification calls failing, because of not recorded invocations: “Actually, there were zero interactions with this mock.”.