extendwith
Companion code for JUnit @ExtendWith Explained (JUnit 5 and 6): Write Your First Extension on ankurm.com. Deeper extension material: JUnit 6 extensions, advanced extensions.
Three small extensions (a timing extension, a ParameterResolver, a TestExecutionExceptionHandler) and fixtures that show where @ExtendWith can go, in which order extensions run, and how @RegisterExtension and ServiceLoader registration differ. Every transcript quoted in the article is in output/.
Versions
| Component | Version |
|---|---|
| JUnit Jupiter (default) | 6.1.3 (GA 2026-08-07) |
JUnit Jupiter (-Pjunit5) |
5.14.4, Platform 1.14.4 |
Mockito (mockito-junit-jupiter) |
5.24.0 |
| JDK | 25 (maven.compiler.release 25); the extensions also compile with --release 17 |
Run
mvn test # JUnit 6.1.3 -> output/01..08, 13
mvn -Pjunit5 test # JUnit 5.14.4 -> output/junit5/ (same sources, identical transcripts)
scripts/run-all.sh # both, plus the javap/javac probes -> output/09..12
Needs JDK 17+ and Maven; scripts/versions.sh downloads a few jars from Maven Central.
Files
| Path | What |
|---|---|
src/test/java/.../ext/ |
The extensions: TimingExtension, ApiKeyResolver, NetworkTimeoutHandler, LifecycleExtension, First/SecondExtension, TimedTest (composed annotation), and the earlier post's PerformanceTrackerExtension, TransactionalExtension, TempDirectoryExtension |
src/test/java/.../fixtures/ |
Test classes that the Platform runs on demand (excluded from Surefire) |
ExtendWithTest.java, Runner.java |
Start the Platform on one fixture at a time, write output/NN-*.txt, assert the same facts |
src/test/resources/META-INF/services/ |
ServiceLoader registration of AutoRegisteredExtension |
src/spring/UserProfileServiceTest.java |
The earlier post's Spring snippet: compiled by scripts/versions.sh, not executed |
output/01-levels.txt ... 13-lifecycle-order.txt |
Captured evidence, see the article for which block each one backs |
Honest limits
Millisecond figures are masked as N in the transcripts (the tests assert lower bounds instead). TempDirectoryExtension only logs; it creates no directory. Output 12 proves the Spring snippet compiles, nothing more.