There is no documented roadmap to change the default execution order to a deterministic sequence. The unspecified order is a deliberate architectural standard designed to enforce test isolation and discourage the creation of hidden dependencies between test cases.
Architectural Intent vs. Reproducibility
JUnit 5 prioritizes test independence. If a test suite only passes when executed in a specific sequence, it indicates a leak in state or a failure in the @BeforeEach/@AfterEach cleanup logic. By keeping the default order nondeterministic, the framework forces these "brittle" tests to fail early in development or CI, rather than masking the issue until a runtime environment change occurs.
Confirmed Behavior
- Default State: The order is unspecified and may vary between JVM implementations, OS environments, or JUnit versions.
- Explicit Overrides: Determinism is only guaranteed when a
MethodOrderer is explicitly provided via the @TestMethodOrder annotation.
Implementing Determinism Without Manual Overhead
If your suite requires reproducibility for debugging or auditing without manually annotating every single method, use a class-level alphanumeric orderer. This provides a stable sequence based on method names without requiring @Order annotations on every test.
import org.junit.jupiter.api.*;
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
class ReproducibleTestSuite {
@Test
void testA_Initialization() { ... }
@Test
void testB_Processing() { ... }
}
Verification Steps
- Run the suite without
@TestMethodOrder across different environments (e.g., local vs. CI) to confirm the nondeterministic sequence.
- Apply
MethodOrderer.Alphanumeric.class to the class.
- Verify that the execution sequence remains identical across all environments.
Diagnostic Detail Needed: Are you experiencing intermittent failures (flakiness) that disappear when order is enforced, or is the requirement for determinism purely for audit/logging purposes? If the former, the issue is shared state, not execution order.