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
- WIP Enable parallel execution for most tests [ECR-534]: The results are not very promising — a "hot" `mvn verify` (= no native ITs) takes 5-8 s less (from 01:14 min to 01:06-01:09 min — but I haven't... — committed to dmitry-timofeev/exonum-java-binding-1 by dmitry-timofeev 5 years ago
- WIP Enable parallel execution for most tests [ECR-534]: The results are not very promising — a "hot" `mvn verify` (= no native ITs) takes 5-8 s less (from 01:14 min to 01:06-01:09 min — but I haven't... — committed to dmitry-timofeev/exonum-java-binding-1 by dmitry-timofeev 5 years ago
- WIP Enable parallel execution for most tests [ECR-534]: The results are not very promising — a "hot" `mvn verify` (= no native ITs) takes 5-8 s less (from 01:14 min to 01:06-01:09 min — but I haven't... — committed to dmitry-timofeev/exonum-java-binding-1 by dmitry-timofeev 5 years ago
- Optimize the build [ECR-534]: (#954) - Add Maven JVM configuration files that improve the build time, according to the experiments (see Jira) - Make all tests parallel-execution friendly. The re... — committed to exonum/exonum-java-binding by dmitry-timofeev 5 years ago
- Bumped JUnit Jupiter and added a test Added a test to enhance coverage. We need higher version of JUnit Jupiter to reproduce and fix #1630 — committed to mockito/mockito by mockitoguy 5 years ago
- Fixed JUnit Jupiter parallel issue Fixes #1630 This fix improves Mockito JUnit Jupiter extension. However, it does not completely resolve all kinds of parallel issues when nested test classes are us... — committed to mockito/mockito by mockitoguy 5 years ago
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.”.