From the root of an existing Maven project, run ./mvnw test; for Gradle, run ./gradlew test. On Windows, use mvnw.cmd test or gradlew.bat test. If your repository has no wrapper, use the installed mvn or gradle command. A direct Java command is also possible with the JUnit Platform Console Launcher, but it requires compiled test classes and their runtime dependencies.
Choose the command that matches your project
Use the build system already configured in the repository. Its wrapper selects the project’s intended Maven or Gradle distribution and is usually the right choice for local work and CI.
| Route | Best fit | Main requirement | Typical command |
|---|---|---|---|
| Maven | An existing Maven project | Surefire or Failsafe and the required JUnit engine are configured | ./mvnw test |
| Gradle | An existing Gradle project | The test task uses the JUnit Platform and has a test engine on its runtime classpath | ./gradlew test |
| JUnit Console Launcher | A direct Platform invocation, such as when there is no build task | Compiled test classes and the complete runtime classpath | java -jar junit-platform-console-standalone-<aligned-version>.jar execute ... |
These routes are not universally faster or better. Choose based on the build system, required test selection, and whether the project already manages dependencies. The JUnit team documents Maven and Gradle support in the JUnit User Guide’s build support section.
Run tests with Maven
Use the Maven wrapper
From the repository root, run:
./mvnw test
On Windows Command Prompt or PowerShell, use:
mvnw.cmd test
Use installed Maven if there is no wrapper
Run mvn test on macOS, Linux, or Windows. If the shell says the command cannot be found, install Maven or use the repository’s wrapper if present.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
Run one test class
A common Maven Surefire pattern is:
./mvnw -Dtest=MyTest test
Replace MyTest with the test class name. Selection behavior can depend on the Surefire version and project configuration; consult the Maven Surefire single-test documentation if this pattern does not select the class as expected.
Maven’s Surefire and Failsafe support JUnit Platform execution. The exact plugin and dependency versions depend on the project’s JUnit major version and build setup, so avoid pinning versions without checking the current JUnit build support guidance.
Run tests with Gradle
Run the test task
From the repository root, run:
./gradlew test
On Windows, use gradlew.bat test. If there is no wrapper, run gradle test if Gradle is installed.
Rank #2
Configure the JUnit Platform when needed
For Jupiter or other JUnit Platform tests, the Gradle test task needs to use the Platform. In a Groovy build.gradle, the canonical configuration is:
Free tools Windows power users keep installed
One-click scans. No signup required.
test {
useJUnitPlatform()
}
A Kotlin DSL build.gradle.kts uses different syntax; do not paste the Groovy block into it unchanged. Gradle also supports filtering by tags or engines through the useJUnitPlatform configuration. The matching test engine must be available on the test runtime classpath. See the JUnit build support guide and Gradle’s Java testing documentation.
Run tests directly with the JUnit Console Launcher
The Console Launcher is a command-line Java application for launching the JUnit Platform. Use it when you need a direct Platform invocation rather than the project’s normal Maven or Gradle test task. The standalone JAR bundles the launcher’s dependencies, but it does not compile your project or supply arbitrary application dependencies.
Scan the classpath
Download the standalone artifact aligned with the JUnit version used by the project, then run:
java -jar junit-platform-console-standalone-<aligned-version>.jar execute --scan-classpath
Select a test class
To run a specific fully qualified class, use:
java -jar junit-platform-console-standalone-<aligned-version>.jar execute --select-class com.example.MyTest
Replace com.example.MyTest with the actual package and class name. This can help distinguish a selector problem from an overly broad classpath scan.
Supply compiled tests and dependencies
If your classes are outside the JAR, add the application and test output directories and all required runtime dependencies to the classpath. The separator differs by operating system: Unix-like shells use :, while Windows uses ;. There is no single portable classpath command that fits every project layout. Consult the JUnit Console Launcher documentation for the current invocation and option details.
Rank #4
The guide documents exit status 1 when a test or container fails. An empty discovery run can return 0 unless you use --fail-if-no-tests; with that option, no discovered tests returns 2. For automation, failing on an empty run helps prevent a successful command from masking a scan of the wrong location.
Check the JUnit version, Java runtime, and engine
Confirm the Java requirement
Check the runtime used by the command with:
java -version
JUnit 6.0 requires Java 17 or newer, according to the JUnit team’s September 30, 2025 release notes. Do not apply that minimum automatically to JUnit 5 projects: check the project’s JUnit major version and its Java toolchain settings.
Make sure the right engine is present
The JUnit Platform is the execution infrastructure, not the test API itself. Jupiter is the engine for JUnit Jupiter tests; Vintage enables JUnit 4 tests to run on the Platform. If JUnit 4 tests are missing from Platform execution, check that JUnit 4 and the Vintage engine are available at test runtime. For Jupiter tests, ensure the Jupiter engine is available.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
Keep dependency versions aligned
JUnit recommends aligning Platform, Jupiter, and Vintage artifacts, commonly with the JUnit BOM. If Spring Boot manages JUnit dependencies for the application, check its dependency management before adding another BOM. The JUnit team covers both practices in its build support guidance and Spring Boot guidance.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot failed or empty runs
- The command is not found: Check the repository root for
mvnworgradlew. Use the matching wrapper command, or install the build tool and usemvn testorgradle test. - The build succeeds but reports no tests: Verify the conventional test source directory, class and method naming, any build-tool filters, and the runtime classpath. Confirm a suitable test engine is present. With the Console Launcher, try
--select-classfor a known test class to check whether broad scanning is the issue. - JUnit 4 tests are missing in Platform runs: Check that the Vintage engine and JUnit 4 are on the test runtime classpath.
- Java version errors appear: Run
java -versionin the same environment as the test command and check the project toolchain. JUnit 6 requires Java 17 or later. - JUnit dependency conflicts appear: Align the JUnit artifacts with the BOM, or use the versions managed by Spring Boot if the project relies on it.
- The standalone launcher cannot load tests: Compile the tests first, then ensure the test output directory, application classes, and non-JUnit runtime dependencies are all on the classpath. The standalone JAR supplies the launcher’s dependencies, not your project’s compiled code.
- CI passes despite running zero tests: For Console Launcher runs, enable
--fail-if-no-testsso an empty discovery result returns a failing exit status.
Or skip the browser setup
JUnit runs tests; ScreenshotNeo captures website screenshots, so it is not a JUnit runner or a replacement for Maven, Gradle, or the Console Launcher. If your command-line workflow also needs a website screenshot, one GET request returns an image or PDF. For example, save a WebP screenshot with cURL:
Quick Recap
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. ScreenshotNeo removes cookie banners, popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo, or sign up free.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitches




