Fix No Matching Tests Found in Gradle

Gradle shows “No matching tests found in any candidate test task” because it was asked to run a particular test class, method, or filter, but none of the available Gradle test tasks discovered a test matching that request. The test may still exist and run from your IDE; the usual problem is a stale run configuration, an incorrect fully qualified class name, the wrong module or test task, or test code that Gradle is not configured to discover.

Use this table to identify the likely branch before changing your build.

What You See Likely Cause First Fix to Try
The IDE runs the test, but a Gradle test run fails The IDE sent Gradle an outdated class, method, module, or package name Run the full Gradle test task, then recreate the targeted run configuration
./gradlew test succeeds but runs no tests Tests are outside Gradle’s configured test source set, or the test framework is not configured Check src/test/java, test dependencies, and JUnit Platform configuration
The full suite runs, but --tests fails The requested class name or filter does not exactly match the compiled test Correct the package and class name used in the filter
Tests are in another Gradle module Gradle is running the root project’s test task instead of the module’s task Run the module-qualified task, such as :module-name:test
The failure appears only for a package beginning with a capital letter A Gradle tooling filter can mishandle nonstandard uppercase package names Rename the Java package to lowercase and refresh the Gradle project
Only integration or tagged tests fail to start The relevant custom task, include/exclude rule, or JUnit tag filter is excluding them Run the correct test task and review its filters

What the Gradle Error Means

This is a test-selection error, not a failed assertion and not necessarily a compilation error.

A Gradle build can contain more than one task capable of running tests. Common examples include a root project’s test task, a subproject’s test task, and custom tasks such as an integration-test task. When an IDE or command asks Gradle to run one specific test, Gradle checks the eligible test tasks for a matching discovered test.

If the request says something like:

Requested tests:
Test class com.example.LibraryTest

Gradle is looking for a compiled test whose fully qualified class name is exactly com.example.LibraryTest. It is not looking for a source file called LibraryTest.java somewhere in the project. The package declaration, compiled class name, selected project, and selected task all have to line up.

A successful Gradle task does not prove that tests ran; it only proves that Gradle found no build failure. A filtered test request is useful because it turns an empty or incorrect selection into a visible error.

How to Fix No Matching Tests Found in Any Candidate Test Task

Step 1: Run the Full Test Task Without a Filter

Start by removing the class or method selection. This separates a filtering problem from a broader discovery problem.

From the project root, run:

./gradlew test

If the tests belong to a subproject, run that project’s test task instead:

./gradlew :module-name:test

Interpret the result before moving on:

  1. If the full task runs your tests, Gradle can discover them. The problem is the targeted test name, method, module, or IDE run configuration.
  2. If the task succeeds but runs no tests, Gradle is not discovering your test classes. Check whether Gradle recognizes the test source layout and has the required framework setup.
  3. If compilation fails, fix the compilation or dependency problem first. Gradle cannot select a test class that did not compile.

Do not start with clean as the main fix. Cleaning can force Gradle to rebuild output, but it does not correct a wrong test name, package, or task selection.

Step 2: Verify the Requested Test Class Name

A fully qualified class name, package name plus class name, is a reliable filter for a specific test.

For example, if the test file begins with:

package com.example.billing;
class InvoiceServiceTest {
    // tests
}

the class filter must use:

./gradlew test --tests "com.example.billing.InvoiceServiceTest"

Check these details carefully:

  1. Read the package declaration in the test source file. Do not infer it only from the folder name.
  2. Confirm the class name, including capitalization.
  3. Make sure the class was not renamed or moved after you created the IDE run configuration.
  4. Do not use a filesystem path such as src/test/java/com/example/billing/InvoiceServiceTest.java.
  5. If the test belongs to a subproject, run that subproject’s test task rather than the root task.

If the command-line class filter works but the IDE action still fails, delete and recreate that IDE test configuration. It is likely holding an old class name, package, or Gradle project path.

Step 3: Make Sure Gradle Can Discover the Test Source Set

For a standard Java Gradle project, application code belongs under src/main/java and test code belongs under src/test/java.

A conventional layout looks like this:

project/
├── src/
│   ├── main/
│   │   └── java/
│   │       └── com/example/app/
│   └── test/
│       └── java/
│           └── com/example/app/
└── build.gradle

If your test is in a custom folder, Gradle will not automatically treat it as test code unless you configure a source set for that location. Moving the test into src/test/java is usually simpler than maintaining a custom source-set configuration.

Also confirm that your package declaration matches the source structure:

package com.example.app;

should normally be located under:

src/test/java/com/example/app/

Then check test dependencies. JUnit belongs on the test classpath, not the application’s production classpath. In Gradle terms, use testImplementation for JUnit dependencies rather than implementation.

For JUnit 5, Gradle must also be told to use the JUnit Platform:

test {
    useJUnitPlatform()
}

A JUnit 5 test can compile in an IDE while Gradle still fails to execute it if the JUnit Platform is not enabled for the Gradle test task or the required engine is missing from the test runtime classpath.

Step 4: Run the Test Task That Owns the Test

In a multi-project build, the root test task does not automatically mean “run every test in every module.” A test in :service needs the :service:test task; a test assigned to a custom integration-test source set may need a separate task.

For example:

./gradlew :service:test --tests "com.example.service.UserServiceTest"

Check the Gradle task selected by your IDE run configuration. A configuration can point at the wrong project after a module is renamed, moved, or re-imported.

Custom test tasks can also have restrictions that intentionally leave no matching tests:

  • include or exclude patterns
  • JUnit tag filters
  • framework-specific test filters
  • task-level class filters
  • test source sets separate from the ordinary test source set

Temporarily remove or relax a restrictive filter only long enough to confirm that the class is discoverable. Then restore the filter with the corrected class, tag, or pattern.

Step 5: Refresh the IDE Project and Re-Test the Exact Selection

Once the full Gradle task works and the requested class name is correct, refresh or re-import the Gradle project in your IDE. Then recreate the run configuration if it still refers to an old package, method, task, or module.

In IntelliJ IDEA, set test execution to Gradle under Settings > Build, Execution, Deployment > Build Tools > Gradle, then choose Gradle for the “Run tests using” setting. This makes local IDE runs use the same Gradle test configuration that CI and command-line builds use.

Finally, verify the exact class selection with Gradle and more detailed output:

./gradlew test --tests "com.example.billing.InvoiceServiceTest" --info

If this command runs the intended test, Gradle discovery and filtering are working. An IDE configuration that still fails should be recreated rather than repeatedly edited.

Special Cases That Cause the Error

Uppercase package names, IDE runner differences, and task include or exclude rules can prevent Gradle from matching tests.

An Uppercase Java Package Name

Java package names conventionally use lowercase letters. Beyond convention, an uppercase package segment can cause failures in some Gradle tooling test filters.

For example, a package like this can be troublesome:

package RetestGradleSimple;

Rename it to lowercase:

package retestgradlesimple;

Then update the folder path, imports, and any Gradle or IDE test filters that use the old fully qualified class name. Refresh the Gradle project afterward.

A Test That Runs in the IDE but Not From Gradle

Your IDE can use its own JUnit runner, while Gradle uses the build’s declared source sets, dependencies, and test tasks. That difference explains why a gutter-button run can pass even when Gradle finds no matching test.

Treat Gradle as the source of truth when the build runs in CI. Put the test in Gradle’s test source set, keep JUnit dependencies in the test configuration, enable the JUnit Platform for JUnit 5, and have the IDE delegate tests to Gradle.

A Class Excluded by Task Rules

A class can compile correctly yet never be considered by a particular task because that task has class include/exclude rules or a framework-level tag filter.

This often happens after a project adds separate unit and integration test tasks. A test may belong to the integration task, but an IDE configuration still tries to run it through the unit-test task. Run the task that owns the source set and remove stale task selection from the run configuration.

Selecting JUnit 5 Nested Tests With TestLauncher

Nested JUnit 5 tests need special handling when you select them through Gradle’s TestLauncher. Java source code represents nesting with dots, but the JVM binary class name uses dollar signs.

To select one deeply nested test class, use its JVM-style name:

testLauncher.withJvmTestClasses("com.example.project.NestedTests$NestedClassB$ADeeperClass");

Do not use a source-style nested name such as NestedTests.NestedClassB.ADeeperClass for that TestLauncher class selection.

If you want to match a top-level test class and its nested test classes, use a wildcard:

testLauncher.withJvmTestClasses("com.example.project.NestedTests*");

This is especially useful when an IDE or tool creates a TestLauncher request for a nested class and a source-code-style class name would otherwise match nothing.

How to Confirm the Fix and Prevent It Returning

Use this short checklist after making changes:

  • The unfiltered Gradle test task executes the expected tests.
  • The test class is under src/test/java or an explicitly configured test source set.
  • The file’s package declaration, directory, and filtered fully qualified class name agree.
  • JUnit dependencies are in the test configuration rather than the production configuration.
  • JUnit 5 builds enable useJUnitPlatform().
  • The selected Gradle task belongs to the correct module and source set.
  • IDE test runs are delegated to Gradle when you need local behavior to match CI.
  • Saved run configurations have been recreated after package, class, module, or task changes.

When diagnosing a stubborn case, change one variable at a time: first prove that the full Gradle suite runs, then prove that the exact class filter works, and only then restore method-level or IDE-specific selection.

Frequently Asked Questions

Is “No Matching Tests Found” the Same as a Failed Test?

No. It means Gradle did not find a discovered test matching the requested class, method, or filter. No assertion had to run or fail for this error to appear.

A real test failure normally identifies the test that executed and shows an assertion error, exception, or failed expectation.

Why Does My Test Run From IntelliJ IDEA but Not With Gradle?

IntelliJ IDEA may use its own test runner, while Gradle uses your build’s source sets, dependencies, and configured test task. A test can therefore run from the editor even when it is outside src/test/java, missing from the Gradle test runtime, or assigned to a different Gradle module.

Set IntelliJ IDEA to use Gradle under Settings > Build, Execution, Deployment > Build Tools > Gradle when you want IDE runs to match Gradle and CI behavior.

Can an Uppercase Package Name Cause This Error?

Yes. A Java package beginning with an uppercase letter can trigger a Gradle tooling filter problem in some environments. Rename the package with lowercase segments, update its directory and imports, then refresh the Gradle project and recreate the affected test run configuration.

How Do I Run a Nested JUnit 5 Test Through TestLauncher?

Use the nested class’s JVM binary name, with dollar signs between nested classes. For a deeply nested class, use withJvmTestClasses("com.example.project.NestedTests$NestedClassB$ADeeperClass").

To include a top-level nested-test container and its nested classes, use withJvmTestClasses("com.example.project.NestedTests*").

Will Running clean Fix No Matching Tests Found?

Usually not. clean removes build output, but it does not fix an incorrect package name, a stale test filter, the wrong Gradle module, or a missing JUnit Platform configuration.

Start with an unfiltered ./gradlew test, then correct the selected class name, test task, source layout, or framework configuration based on what that run reveals.