tl;dr
testImplementation(platform("org.junit:junit-bom:6.0.0-RC1"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.junit.vintage:junit-vintage-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
junit-jupiter aggregator artifact
JUnit 5.4+ provides much simpler Maven configuration if your intent is to write JUnit 5 tests. Simply specify the aggregate artifact named junit-jupiter.
In Maven syntax:
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.13.4</version>
<scope>test</scope>
</dependency>
As an aggregate, this artifact in turn pulls the following three artifacts automatically, for your convenience:
In your project, you will also end up with:
- junit-platform-commons-5.13.4.jar
- junit-platform-engine-5.13.4.jar
The above is what you need to write and run JUnit 5 tests based on the new Jupiter paradigm.
Legacy tests
If your project has JUnit 3 or 4 tests that you want to continue to run, add another dependency for the JUnit Vintage Engine, junit-vintage-engine. See tutorial by IBM.
In Maven syntax:
<!-- https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.13.4</version>
<scope>test</scope>
</dependency>
Gradle
The equivalent in Gradle, in the now-recommended Kotlin DSL (syntax), in a build.gradle.kts file:
dependencies {
// JUnit
testImplementation(platform("org.junit:junit-bom:6.0.0-RC1"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.junit.vintage:junit-vintage-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
Gradle 9, JUnit 6
You may want to see this Answer and this Answer](https://stackoverflow.com/a/79746408/642706) of mine covering the use of the new Gradle 9 with the new JUnit 6 on Java 24 and Java 25 respectively.
testRuntimefor both engines.