Below are the changes worth knowing, each with a short, runnable-style example.

1. Java 17 as prerequisite

JUnit 6 requires Java 17 or higher. Java 8–16 support is gone. This lets JUnit’s own code use modern language features internally, and it matches where the rest of the ecosystem (Spring 6, Spring Boot 3, AssertJ) already sits.

2. One Version Number for Everything

Previously, junit-jupiter, junit-platform, and junit-vintage had independent version numbers (e.g. Jupiter 5.10 used Platform 1.10). In JUnit 6, all modules share the same version: 6.0.0, 6.0.1, and so on. Dependency management gets simpler — one BOM version, no more mismatched module versions.

xml

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>6.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

3. CancellationToken and Fail-Fast

JUnit 6 introduces a CancellationToken API so a test run can be stopped cooperatively — useful for CI, where you want to abort a slow suite the moment something fails instead of burning more compute.

java

import org.junit.platform.engine.CancellationToken;
import org.junit.platform.launcher.*;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
import static org.junit.platform.launcher.core.LauncherExecutionRequestBuilder.executionRequest;
class FailFastRunner {
public static void main(String[] args) {
CancellationToken token = CancellationToken.create();
TestExecutionListener failFast = new TestExecutionListener() {
@Override
public void executionFinished(TestIdentifier id, TestExecutionResult result) {
if (result.getStatus() == TestExecutionResult.Status.FAILED) {
token.cancel(); // stop the run on first failure
}
}
};
var discovery = request().selectors(selectClass(MyTests.class)).build();
var execution = executionRequest(discovery)
.cancellationToken(token)
.listeners(failFast, new SummaryGeneratingListener())
.build();
LauncherFactory.create().execute(execution);
}
}

4. Deterministic Ordering for @Nested Classes

In JUnit 5, the execution order of @Nested classes was unspecified-but-stable, which sometimes confused people relying on declaration order. JUnit 6 makes nested test ordering deterministic, and @TestClassOrder / @TestMethodOrder on an outer class is now inherited by its @Nested classes.

java

import org.junit.jupiter.api.*;
@TestClassOrder(ClassOrderer.OrderAnnotation.class)
class OrderedNestedDemo {
@Nested
@Order(1)
class PrimaryTests {
@Test
void runsFirst() { /* ... */ }
}
@Nested
@Order(2)
class SecondaryTests {
@Test
void runsSecond() { /* ... */ }
}
}

No more guessing which nested class runs first — @Order settles it, and child classes don’t need to repeat the annotation.

5. CSV Parsing Moved to FastCSV

@CsvSource and @CsvFileSource used to rely on univocity-parsers, which is no longer maintained. JUnit 6 switches to FastCSV: faster, RFC 4180 compliant, zero extra dependencies, and stricter about malformed input (a trailing character after a closing quote, which used to be silently accepted, now throws).

java

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
class CsvDemo {
@ParameterizedTest
@CsvSource({
"apple, 3",
"banana, 5"
})
void countsFruit(String name, int count) {
Assertions.assertTrue(count > 0);
}
}

The annotation usage is identical — what changed is under the hood. If your test data has a stray quote or relies on a custom lineSeparator attribute in @CsvFileSource, check it: that attribute was removed (line endings are now auto-detected), and malformed quoting is now a hard error instead of a silent pass.

6. Removed and Trimmed Modules

A few modules disappeared in the cleanup:

  • junit-platform-runner — removed.
  • junit-platform-jfr — removed as a separate module; its Java Flight Recorder support is now built into junit-platform-launcher.
  • junit-platform-suite-commons — folded into junit-platform-suite.
  • junit-jupiter-migrationsupport — deprecated, slated for removal next major version.

Hinterlasse einen Kommentar

I’m Iman

Mein Name ist Iman Dabbaghi. Ich arbeite als Senior Software Engineer in der Schweiz. Außerdem interessiere ich mich sehr für gewaltfreie Kommunikation, Bachata-Tanz und Musik sowie fürs die Persönlichkeitsentwicklung.

Ich habe einen Masterabschluss in Informatik von der Universität Freiburg in Deutschland, bin Spring/Java Certified Professional (OCP), Certified Professional for Software Architecture (CPSA-F) und ein lebenslanger Lernender 🎓.

EN:

My name is Iman Dabbaghi. I work as a Senior Software Engineer in Switzerland. I am also very interessted in nonviolent communication, Bachata dance and music and also for personal development.

I hold a masters degree in computer science from the university of Freiburg in Germany, am a Spring / Java Certified Professional (OCP), Certified Software Architecture (CPSA-F) and Life Long Learner🎓

Let’s connect