Files
JUnit_Tutorials/organising/src/broken/MethodOrdererDefaultDemo.java
T
asmhatreandClaude Sonnet 5 bfc67986bc Add organising module: DisplayNameGenerator/@Nested/@Tag demos on JUnit 6.1.3
Companion code for the rewritten post "Organising and Displaying JUnit Tests:
@DisplayName, @Nested, @Tag (JUnit 5 -> JUnit 6)". Same suite also runs green
on JUnit 5.14.4 via -Djunit.version. Verified, not assumed: GA dates and
versions cross-checked against Maven Central metadata and docs.junit.org
release notes; the @TestMethodOrder-inheritance-into-@Nested-classes and
MethodOrderer.Default/ClassOrderer.Default behaviour differences between
5.14.4 and 6.1.3 are demonstrated by actually running the same source under
both engines (see organising/output/12-* and 14-*), not by reading about them.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YXCrLgRKFgCh9RHKW8xaqJ
2026-10-01 04:38:28 +00:00

29 lines
1.0 KiB
Java

package com.ankurm.tutorials.junit.organising.broken;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
/**
* Excluded from the normal build (lives under src/broken, not src/test). Compiles on JUnit
* 6.1.3 and fails on JUnit 5.14.4: MethodOrderer.Default was added in JUnit 6.0 to let a @Nested
* class opt back out of an outer class's inherited @TestMethodOrder - see scripts/broken-compile.sh
* and output/15-broken-compile-6.1.3.txt / output/16-broken-compile-5.14.4.txt for the real
* compiler output on both versions.
*/
@TestMethodOrder(MethodOrderer.MethodName.class)
class MethodOrdererDefaultDemo {
@Test void charlie() {}
@Test void alpha() {}
@Test void bravo() {}
@Nested
@TestMethodOrder(MethodOrderer.Default.class) // <-- does not exist before JUnit 6.0
class OptedBackOutOfInheritedOrdering {
@Test void zulu() {}
@Test void yankee() {}
@Test void xray() {}
}
}