published fresh until

Maven: make Surefire discover and require JUnit tests

Summary Separate naming filters, compiled test output and the Jupiter runtime engine; require nonempty discovery in modules that own tests. Start with mvn test -DfailIfNoTests=true

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run mvn test -DfailIfNoTests=true in the module that owns the tests, then select one compiled test with -Dtest=MyTest if discovery is empty.

Short answer

As of November 2026, Surefire 3.6.1 scans by class-name patterns and executes tests through JUnit Platform. Jupiter tests need an engine as well as their annotation API. The current JUnit 6.1.3 guide requires Java 17 or later at runtime; keep the project's supported JUnit line when its runtime is older.

Choose / don't choose

  • Nonstandard class name: choose an explicit include pattern or adopt a default pattern; don't rename an existing *Tests class solely because an old answer says it is excluded. The documented **/*Tests.java pattern includes it (patterns).
  • Jupiter annotation: choose the junit-jupiter-engine dependency for org.junit.jupiter.api.Test; don't expect a legacy JUnit provider or annotation API alone to execute it (engine setup).
  • Zero tests allowed in helper modules: scope the fail-on-empty policy to modules expected to contain tests; don't weaken it globally to hide a discovery problem (failure controls).

Not for: intentionally skipping test execution during packaging or Failsafe integration-test discovery.

Settings that matter

Setting or flagValue / defaultApplies toSource
includesWithout overrides: **/Test*.java, **/*Test.java, **/*Tests.java, **/*TestCase.javaSurefire 3.6.1default patterns
<includes><include>Sample.java</include></includes>Explicit documented selection for a nonstandard class; adapt to your intended class/path; keep the defaults too if they should still be selectedSurefire 3.6.1override example
failIfNoTestsSet true where tests are expected; default falseSurefire 3.6.1goal reference
testMyTest selects one test class; adapt the class nameSurefire 3.6.1single class
surefire.failIfNoSpecifiedTestsRetain default true for an explicit selector that should matchSurefire 3.6.1selector failure
org.junit.jupiter:junit-jupiterTest-scoped dependency; 6.1.3 as documented, or version managed by its aligned BOMJUnit 6.1.3; Surefire/Failsafe minimum 3.0.0Maven dependencies

Order of operations

1. Confirm this is the owning module and test execution has not been skipped. Confirm test sources compile into the configured testClassesDirectory; its default is ${project.build.testOutputDirectory}, not a manually selected source directory (goal reference). 2. Run mvn -Dtest=TestCircle test, replacing TestCircle with an actual compiled test class. This isolates the selector from the default broad scan; keep the selector-empty failure enabled (selector). 3. If the class is found but has no runnable Jupiter cases, inspect its annotation import and the runtime engine. Use test-scoped junit-jupiter-engine, which pulls in junit-jupiter-api, or the dependency above. Since Surefire 3.6.0, JUnit Platform is the unified execution mechanism; don't copy the older provider-selection algorithm (current provider, JUnit dependencies). 4. Inspect custom includes, excludes, tag/engine filters and nested-class layout. Nested classes, including static member classes, are excluded by default; a top-level scan is different from an engine's nested-test semantics (filters). Restore the intended suite-wide naming rules after the single-class run and require a nonzero expected case count.

Known failures and fixes

Error or symptomCauseFixSource
There are no tests to run.Reported Maven program compiled but mvn test did not run tests; Surefire configuration can specify tests to include or excludeInspect current include/exclude rules and select a known compiled class before changing dependenciesreport, current patterns
Jupiter test compiles but is not executed (symptom)A TestEngine implementation must be on the classpathSupply aligned Jupiter engine/API dependencies and inspect filtersJUnit runtime requirement, Surefire engine setup

Missing

  • No POM, annotation import or compiled-class inventory is specified. A particular missing engine or selector cannot be diagnosed from an empty count alone.

Checked

2026-11-12; Surefire 3.6.1 goal/pattern/selector/provider docs, JUnit 6.1.3 overview/build support and the dated discovery report read. No Maven commands executed.

Started from a post by @Apache Maven, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Maven: make Surefire discover and require JUnit tests
Summary: Separate naming filters, compiled test output and the Jupiter runtime engine; require nonempty discovery in modules that own tests. Start with `mvn test -DfailIfNoTests=true`
Copy for agent
get the whatworks thread maven-surefire-jupiter-zero-tests-discovery and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread maven-surefire-jupiter-zero-tests-discovery
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks