Power Your Software Testing with AI Agents and Cloud
The Native AI-Agentic Cloud Platform to Supercharge Quality Engineering. Test Intelligently and Ship Faster.
- TestMu AI (Formerly LambdaTest)
- /
- Learning Hub
- /
- JUnit Maven Dependency: JUnit 5, JUnit 6, and Surefire Setup
JUnit Maven Dependency: JUnit 5, JUnit 6, and Surefire Setup
The JUnit Maven dependency for JUnit 5 and 6: junit-jupiter coordinates, the artifacts you need, junit-bom, Surefire and Gradle setup, and common errors.
Published on:
The JUnit Maven dependency for JUnit 5 and JUnit 6 is org.junit.jupiter:junit-jupiter with test scope. Add it to pom.xml with a current maven-surefire-plugin, run mvn test, and Maven discovers and runs your Jupiter tests. This chapter explains what the aggregator pulls in, when you need the API, engine, params, and launcher artifacts separately, how junit-bom keeps versions aligned, the Gradle equivalent, how JUnit 4 tests fit in through Vintage, and the fixes for the errors people hit most.
This chapter is part of the JUnit tutorial, which covers setup, annotations, assertions, parameterized tests, and Selenium runs.
TL;DR
- One dependency: org.junit.jupiter:junit-jupiter, scope test. The current release on Maven Central is 6.1.3 and needs Java 17; the last JUnit 5 line, 5.13.x, runs on Java 8.
- Pair it with maven-surefire-plugin 3.x. Surefire 2.x predates JUnit 5 and silently runs nothing.
- Import junit-bom under dependencyManagement when you declare more than one JUnit artifact.
- Gradle: testImplementation 'org.junit.jupiter:junit-jupiter:6.1.3' and test { useJUnitPlatform() }.
JUnit 5 and JUnit 6 Maven Dependency
Add this to the dependencies element of pom.xml. The version is the current release on Maven Central at the time of writing; check the junit-jupiter listing before you pin it in a long-lived build. Projects that must stay on Java 8 or 11 use the latest 5.x version with the same coordinates.
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>6.1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
junit-jupiter is an aggregator: it has no code of its own and depends on junit-jupiter-api, junit-jupiter-engine, and junit-jupiter-params. That is why one line is enough to compile tests, run them, and write parameterized tests. Test scope keeps all of it off the application's runtime classpath.
After saving, reload the Maven project in your IDE so it picks up the new classpath, then create a class under src/test/java with a method annotated @Test from org.junit.jupiter.api. The Write JUnit Test Cases chapter picks up from there.
The JUnit Artifacts and When You Need Each
The aggregator covers the common case. Declare the pieces individually only when you have a reason to, such as a library module that should compile against the API without shipping an engine.
- junit-jupiter-api - the annotations (@Test, @BeforeEach, @Nested) and the Assertions and Assumptions classes. Compile scope for test code, and the only artifact a test-support library needs.
- junit-jupiter-engine - the engine that discovers and runs Jupiter tests. Needed at test runtime; without it the build compiles and runs zero tests.
- junit-jupiter-params - @ParameterizedTest and its sources. Only needed if you write parameterized tests, which the JUnit Parameterized Tests chapter covers.
- junit-platform-launcher - the API build tools and IDEs use to launch engines. Surefire 3.x and Gradle add it themselves; Surefire 2.22 and some IDE runners need it declared with test scope.
- junit-platform-suite - @Suite and @SelectPackages for composing suites in code, the JUnit answer to testng.xml.
- junit-vintage-engine - runs JUnit 3 and 4 tests on the platform; see the JUnit 4 section below.
Aligning Versions with junit-bom
As soon as you declare more than one JUnit artifact, or a library such as Mockito's JUnit extension pulls one in transitively, versions can drift and Jupiter will refuse to start with an UnsupportedClassVersionError or a launcher mismatch. The bill of materials pins them all at once:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>6.1.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
With the BOM imported, no JUnit dependency carries its own version, and upgrading the whole framework is a one-line change. Since JUnit 6, Platform, Jupiter, and Vintage share a single version number, which the BOM reflects; the Migrate from JUnit 5 to JUnit 6 chapter walks through the upgrade.
Surefire Configuration
Maven runs tests through the Surefire plugin, and only Surefire 2.22 or newer understands the JUnit Platform. Pin a 3.x release so the version your build uses does not depend on the Maven default:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.6.0</version>
</plugin>
</plugins>
</build>
No further configuration is needed for discovery. Surefire runs classes whose names match *Test, Test*, *Tests, or *TestCase; a class named LoginSpec is skipped until you add an includes rule. Tags declared with @Tag are selected with groups and excludedGroups, and parallel execution is switched on through junit-platform.properties rather than Surefire, as the Parallel Testing with JUnit 5 chapter shows.
mvn test # every test class Surefire can find
mvn test -Dtest=CalculatorTest # one class
mvn test -Dtest=CalculatorTest#adds # one method
mvn test -Dgroups=smoke # only tests tagged @Tag("smoke")
JUnit in Gradle
dependencies {
testImplementation platform('org.junit:junit-bom:6.1.3')
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
test {
useJUnitPlatform()
}
The platform(...) line imports the BOM, and useJUnitPlatform() switches the test task from the JUnit 4 default to the platform. Gradle 9 requires the launcher on the test runtime classpath explicitly, which the testRuntimeOnly line provides. Kotlin DSL users write the same three dependencies with parentheses and tasks.test { useJUnitPlatform() }.
JUnit 4 Dependency and Vintage
JUnit 4 is the artifact junit:junit, and 4.13.2 is its final release. A project that still has JUnit 4 tests can run them on the JUnit 5 platform next to new Jupiter tests by adding the Vintage engine, which lets you migrate class by class instead of all at once:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
JUnit 6 still ships Vintage but marks it deprecated, so treat it as a bridge. The JUnit 4 vs JUnit 5 vs JUnit 6 chapter lists the annotation renames and the migration steps.
Troubleshooting the JUnit Maven Dependency
- Tests run: 0. Surefire is 2.x, or only junit-jupiter-api is declared. Pin Surefire 3.x and use the junit-jupiter aggregator.
- Package org.junit.jupiter.api does not exist. The test lives under src/main/java, or the IDE has not reloaded the project. Move it to src/test/java and reload Maven.
- UnsupportedClassVersionError. JUnit 6 is compiled for Java 17 and the build runs on an older JDK. Point JAVA_HOME at 17 or newer, or stay on the 5.x line.
- Tests run in the IDE but not in Maven. The class name does not match Surefire's include pattern. Rename it or add an includes block.
- NoSuchMethodError inside org.junit.platform. Mixed versions of Platform and Jupiter. Import junit-bom and remove explicit versions from the individual artifacts.
- JUnit 4 tests are ignored. Vintage is missing, or the JUnit 4 test class uses the wrong @Test import. Add junit-vintage-engine and check the import is org.junit.Test.
Conclusion
One junit-jupiter dependency with test scope and a Surefire 3.x plugin are all Maven needs for JUnit 5 and 6; add junit-bom once the project declares more than one JUnit artifact, and Vintage only while JUnit 4 tests remain. With the build in place, the next chapter, Run JUnit from the Command Line, runs the tests without an IDE.
Author
Mohammad Faisal Khatri is a Software Testing Professional with 17+ years of experience in manual exploratory and automation testing. He currently works as a Senior Testing Specialist at Kafaat Business Solutions and has previously worked with Thoughtworks, HCL Technologies, and CrossAsyst Infotech. He is skilled in tools like Selenium WebDriver, Rest Assured, SuperTest, Playwright, WebDriverIO, Appium, Postman, Docker, Jenkins, GitHub Actions, TestNG, and MySQL. Faisal has led QA teams of 5+ members, managing delivery across onshore and offshore models. He holds a B.Com degree and is ISTQB Foundation Level certified. A passionate content creator, he has authored 100+ blogs on Medium, 40+ on TestMu AI, and built a community of 25K+ followers on LinkedIn. His GitHub repository “Awesome Learning” has earned 1K+ stars.
Reviewer
Srinivasan Sekar is Director of Engineering at TestMu AI (formerly LambdaTest), where he leads engineering and open-source initiatives behind the Selenium and Appium automation grid and owns TestMu AI's MCP Server. A committer to Appium and a contributor to Selenium, WebdriverIO, Taiko, and AppiumTestDistribution, he brings over 15 years of experience in quality engineering and open-source technologies. He is the author of the Apress book 'The MCP Standard: A Developer's Guide to Building Universal AI Tools with the Model Context Protocol,' a Certified Kubernetes and Cloud Native Associate, and an international conference speaker. Before TestMu AI he spent over eight years at Thoughtworks as a Principal Consultant and Quality Architect. Srinivasan holds a B.Tech in Information Technology from Anna University.
JUnit Maven Dependency FAQs
Did you find this page helpful?
More Related Learning Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance
- Advanced access controls
- Advanced data retention rules
- Advanced Local Testing
- Premium Support options
- Early access to beta features
- Private Slack Channel
- Unlimited Manual Accessibility DevTools Tests



