cyberangles blog

Class Not Found: Empty Test Suite in IntelliJ – How to Fix 'No Tests Found' for JUnit Beginners

As a beginner diving into Java testing with JUnit, few errors are as frustrating as seeing "Class Not Found: Empty Test Suite" or "No tests found" when you try to run your tests in IntelliJ IDEA. You’ve written what you think is a valid test, clicked "Run," and instead of seeing green checkmarks, you’re met with a cryptic message. What’s going on?

This error typically means IntelliJ cannot detect your test classes or methods, often due to simple configuration oversights, naming conventions, or missing dependencies. The good news is: it’s almost always fixable with a few targeted checks.

In this blog, we’ll break down the most common causes of "No tests found" errors in IntelliJ for JUnit beginners and walk through step-by-step solutions to get your tests running smoothly.

2026-02

Table of Contents#

  1. Understanding the "Empty Test Suite" Error
  2. Step-by-Step Solutions
  3. Troubleshooting Flowchart: Quick Checks
  4. Conclusion
  5. References

Understanding the "Empty Test Suite" Error#

Before diving into fixes, let’s clarify what the error means. When IntelliJ says "No tests found" or "Empty Test Suite," it’s telling you:

  • It searched for test classes but didn’t find any matching its criteria, or
  • It found a test class but no valid test methods inside it.

This is rarely due to a bug in IntelliJ itself. Instead, it’s almost always caused by issues in how your test is structured, named, or configured. Let’s troubleshoot!

Step-by-Step Solutions#

1. Verify Test Class Naming Conventions#

JUnit and IntelliJ rely on naming conventions to auto-detect test classes. While not strictly required, IntelliJ’s default test discovery often looks for classes with names ending in Test (e.g., CalculatorTest, UserServiceTest). If your test class has a non-standard name, IntelliJ might overlook it.

Example of a valid test class name:

// Good: Ends with "Test"
public class CalculatorTest { ... }

Common mistakes:

  • Naming the class CalculatorTesting or TestCalculator (IntelliJ may still detect these, but *Test is the most reliable convention).
  • Accidentally using a different suffix (e.g., CalculatorTests with an "s"—this works in some setups but is less consistent).

Fix: Rename your test class to end with Test (e.g., MathUtilsTest instead of MathUtilsTesting).

2. Check Package Structure and Test Directory Setup#

Tests in Java projects are typically stored in a separate directory from production code. For IntelliJ to find your tests, they must reside in the test source directory, and the package structure should mirror your main code.

Where to Place Tests: The src/test/java Directory#

Most Java projects (Maven, Gradle, or plain) use the standard directory layout:

  • Production code: src/main/java/com/yourpackage/
  • Test code: src/test/java/com/yourpackage/

If your test is saved directly in src/main/java (the production directory) or in an unrecognized folder, IntelliJ won’t treat it as a test.

How to Validate in IntelliJ:#

  1. In the Project Explorer (left sidebar), expand your project.
  2. Look for src/test/java. This is the default test source directory.
  3. Ensure your test class is inside src/test/java and uses the same package as the class it’s testing. For example:
    • Production class: src/main/java/com/example/Calculator.java
    • Test class: src/test/java/com/example/CalculatorTest.java

3. Ensure JUnit Dependencies Are Correctly Configured#

If IntelliJ says "Class Not Found," it might mean the JUnit library isn’t available to your project. Without the JUnit dependency, IntelliJ can’t recognize @Test annotations or run tests.

For Maven Projects:#

Check your pom.xml for JUnit dependencies. For JUnit 5 (the latest version), you need two dependencies:

  • junit-jupiter-api: Provides annotations like @Test.
  • junit-jupiter-engine: Runs the tests.

Add these to your pom.xml (within the <dependencies> tag):

<!-- JUnit 5 API (annotations like @Test) -->
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.9.2</version> <!-- Use the latest version -->
    <scope>test</scope> <!-- Only available during testing -->
</dependency>
 
<!-- JUnit 5 Engine (runs the tests) -->
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.9.2</version>
    <scope>test</scope>
</dependency>

Common Maven mistakes:

  • Forgetting the <scope>test</scope> line (JUnit should only be available during testing).
  • Using an outdated JUnit 4 dependency (e.g., junit:junit:4.13.2) with JUnit 5 annotations (they’re incompatible!).

For Gradle Projects:#

In build.gradle, add JUnit 5 dependencies to the testImplementation and testRuntimeOnly configurations:

// JUnit 5 setup for Gradle
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'

Verify dependencies: After adding, right-click your project and select Maven > Reload Project (Maven) or Gradle > Reload Gradle Project (Gradle) to fetch the libraries.

4. Validate Test Method Annotations and Structure#

Even if your class is named correctly, IntelliJ won’t run a test method unless it meets these criteria:

  • Annotated with @Test (from org.junit.jupiter.api.Test for JUnit 5, or org.junit.Test for JUnit 4).
  • public access modifier.
  • Returns void (no return value).
  • Has no parameters.

Example of a valid test method (JUnit 5):

import org.junit.jupiter.api.Test; // Correct import for JUnit 5
 
public class CalculatorTest {
    @Test // Required annotation
    public void testAddition() { // public, void, no parameters
        int result = Calculator.add(2, 3);
        assertEquals(5, result);
    }
}

Common method mistakes:

MistakeExampleFix
Missing @Test annotationpublic void testAddition() { ... }Add @Test above the method.
Private methodprivate void testAddition() { ... }Change to public.
Returns a valuepublic int testAddition() { return 5; }Change return type to void.
Has parameterspublic void testAddition(int a, int b) { ... }Remove parameters (use @ParameterizedTest if you need parameters, but that’s advanced).
Wrong @Test importimport org.junit.Test; (JUnit 4) with JUnit 5 dependenciesUse import org.junit.jupiter.api.Test; for JUnit 5.

5. Confirm IntelliJ’s Test Sources Root Configuration#

IntelliJ needs to know which directory contains your tests. If src/test/java isn’t marked as a Test Sources Root, IntelliJ will treat it as regular production code (or ignore it entirely).

How to Check:#

In the Project Explorer:

  • The src/test/java directory should have a green folder icon (indicating it’s a Test Sources Root).
  • If it’s a plain yellow folder, IntelliJ doesn’t recognize it as a test directory.

How to Fix:#

  1. Right-click src/test/java in the Project Explorer.
  2. Hover over Mark Directory as > Select Test Sources Root.
    • The folder icon will turn green, confirming IntelliJ now recognizes it as a test directory.

6. Run Tests Correctly in IntelliJ#

Even if your test is perfect, running it the wrong way can trigger "No tests found."

Correct Ways to Run a Test:#

  • Run a single test method: Click the green play button next to the method name (in the gutter, left of the code).
  • Run an entire test class: Right-click the test class name in the editor or Project Explorer > Select Run 'CalculatorTest'.
  • Run all tests in a package: Right-click the package (e.g., com.example.tests) > Run Tests in 'com.example.tests'.

Common Mistakes:#

  • Running the entire project (right-clicking the project root and selecting "Run") instead of the test class/method.
  • Accidentally running a production class (e.g., Calculator.java instead of CalculatorTest.java).

7. Update IntelliJ IDEA and JUnit Versions#

Outdated software can cause compatibility issues. For example:

  • Older IntelliJ versions (pre-2020) have bugs with JUnit 5.
  • Using JUnit 5.4 with IntelliJ 2019 might lead to test discovery failures.

Fix:

  • Update IntelliJ: Go to Help > Check for Updates (Windows/Linux) or IntelliJ IDEA > Check for Updates (Mac). Install the latest version.
  • Use the latest stable JUnit 5 version (e.g., 5.9.2 as of 2023). Check Maven Repository for updates.

8. Resolve Build or Compilation Issues#

If your project hasn’t compiled correctly, IntelliJ can’t find the test class (since the .class file is missing).

Signs of a compilation issue:#

  • Red error markers in your test code (fix these first!).
  • The target/test-classes (Maven) or build/classes/test (Gradle) directory is empty or missing your test class.

How to Fix:#

  1. Clean and rebuild the project:
    • Go to Build > Clean Project (clears old compiled files).
    • Then Build > Rebuild Project (recompiles everything).
  2. Use Maven/Gradle to build:
    • For Maven: Open the "Maven" tab (right sidebar) > Expand your project > Lifecycle > Double-click test (runs tests and ensures dependencies are resolved).
    • For Gradle: Open the "Gradle" tab > Tasks > verification > Double-click test.

Troubleshooting Flowchart: Quick Checks#

If you’re short on time, run through this checklist:

  1. Is your test class named XyzTest?
  2. Is the test saved in src/test/java/com/yourpackage/?
  3. Is src/test/java marked as a Test Sources Root (green folder icon)?
  4. Does your test method have @Test, public, void, and no parameters?
  5. Are JUnit dependencies in your pom.xml/build.gradle with test scope?
  6. Did you clean and rebuild the project?

Conclusion#

The "Class Not Found: Empty Test Suite" error in IntelliJ is almost always a configuration or structural issue, not a bug. By following these steps—checking naming conventions, dependencies, test method structure, and IntelliJ’s test directory setup—you’ll resolve the error and get your tests running in no time.

Remember: Testing is a critical skill, and even seasoned developers hit these snags. Stay patient, and use this guide as a reference!

References#