October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Run JUnit Tests from the Command Line

Use your project’s Maven or Gradle wrapper for the usual command-line test run, or invoke the JUnit Platform Console Launcher directly when compiled classes and dependencies are ready.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.Support on Ko-Fi

Troubleshoot failed or empty runs

  • The command is not found: Check the repository root for mvnw or gradlew. Use the matching wrapper command, or install the build tool and use mvn test or gradle 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-class for 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 -version in 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-tests so 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:

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.