Fixtures for the OS, JRE, system property, environment variable and EnabledIf conditions plus a custom ExecutionCondition, run through the JUnit Platform launcher (in-process and in child JVMs) to capture real skip reasons; skipped versus aborted lifecycle; stacking, class-level skips and the deactivate switch; the 2025 article's code compiled as published; and a javap comparison of the condition package in 5.14.4 and 6.1.3. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01G8ikz8xdWuTP5yun8DZ1hk
2.8 KiB
conditional
Companion code for JUnit Conditional Test Execution (JUnit 5 → 6) on ankurm.com. The assumptions half of the story is in JUnit 6 Assumptions.
The condition annotations (@EnabledOnOs, @EnabledOnJre, @EnabledIfSystemProperty, @EnabledIfEnvironmentVariable, @EnabledIf) and the ExecutionCondition extension point, run on JUnit Jupiter 6.1.3 and JDK 25. Every message and result quoted in the article is in output/.
How the evidence is produced
The fixtures in src/test/java/.../fixtures/ are test classes that are meant to be skipped, aborted or to pass depending on the machine. They are excluded from Surefire. ConditionalTest starts the JUnit Platform on one fixture at a time (Runner), collects the result and the skip reason of each test, and writes the evidence file. For things a test cannot change in its own JVM (environment variables, -D flags) it starts a fresh JVM (Child) with the environment it wants.
| File | What it shows |
|---|---|
output/01-os-and-jre.txt |
The 2025 article's OS and JRE examples on this machine, with the real skip reasons |
output/02-architecture.txt |
architectures on @EnabledOnOs / @DisabledOnOs |
output/03-system-properties.txt |
@EnabledIfSystemProperty in three fresh JVMs |
output/04-environment-variables.txt |
@EnabledIfEnvironmentVariable with CI and ENV set and unset |
output/05-custom-condition.txt |
The article's WeekendCondition, and a reusable @EnabledOnDays condition with the day pinned |
output/06-skipped-versus-aborted.txt |
A condition-skipped test never starts; an assumption-aborted one has already run @BeforeEach |
output/07-stacking-and-switches.txt |
Several conditions on one test, disabledReason, @EnabledIf("method"), class-level skips, and switching conditions off |
output/08-old-code-vs-junit-6.txt |
The 2025 article's code blocks compiled exactly as published |
output/09-api-5-vs-6.txt |
org.junit.jupiter.api.condition in junit-jupiter-api 5.14.4 and 6.1.3 compared with javap |
Run
scripts/run-all.sh # tests -> 01..07, then the compile and API comparison -> 08, 09
Needs JDK 17 or newer (built on 25) and Maven. Script 08/09 downloads two jars from Maven Central (it retries on rate limiting).
Honest limits
Outputs 01, 02 and 07 describe the machine they ran on (Linux, amd64, JDK 25.0.4.1), so the OS, architecture and JRE conditions were only observed on that one combination. The first block of 05 depends on the day the tests ran. src/old/ holds the 2025 article's code blocks verbatim; the copy under fixtures/ adds a package line, and for WeekendCondition the Test import that the published block was missing.