Class Not Found: Empty Test Suite in IntelliJ

I'm just starting the computer science program at my college, and I'm having some issues with IntelliJ. When I try to run unit tests, I get the message

Process finished with exit code 1
Class not found: "edu.macalester.comp124.hw0.AreaTest"Empty test suite.

I also see a message entitled "No tests were found" on the left side of my screen. My test code is here:

package edu.macalester.comp124.hw0;


import org.junit.Test;
import static org.junit.Assert.*;

public class AreaTest {

    @Test
    public void testSquare() {
    assertEquals(Area.getSquareArea(3.0), 9.0, 0.001);
    }

    @Test
    public void testCircle() {
    assertEquals(Area.getCircleArea(3.0), 28.2743, 0.001);
    }
}

And my project code is here:

package edu.macalester.comp124.hw0;

import java.lang.Math;
public class Area {

/**
 * Calculates the area of a square.
 * @param sideLength The length of the side of a square
 * @return The area
 */
public static double getSquareArea(double sideLength) {
    // Has been replaced by correct formula
    return sideLength * sideLength;
}

/**
 * Calculates the area of a circle.
 * @param radius The radius of the circle
 * @return The area
 */
public static double getCircleArea(double radius) {
    // Replaced by correct value
    return radius * 2 * Math.PI;
}

}

How can I get my tests to work? I'm using the most recent version of IntelliJ IDEA CE.


Solution 1:

Had the same message. I had to remove the Run/Debug configuration.

In my case, I ran the unit test as a local test before. After that I moved my test to the androidTest package and tried to run it again. Android Studio remembered the last run configuration so it tried to run it again as a local unit test which produced the same error.

After removing the config and running the test again it generated a new configuration and worked.

enter image description here

Solution 2:

I went to

File -> Invalidate Caches/Restart...

and then it worked for me.

Solution 3:

I had the same issue. I rebuilded project, and it helped me.

Go to Build --> Rebuild Project

After then, if you are using Maven tool, I recommend use option Reimport All Maven Projects


If it not help, try another possible solutions:

  • Go to File-->Invalidate Caches/Restart--> Invalidate and Restart

or:

  • In your Maven project structure src/main/java right click on java directory and select option Mark directory as --> Sources Root

    Similarly do the same with test directory so: src/test/java right click on java directory and select option Mark directory as --> Test Sources Root

or:

  • Go to Run --> Edit Configurations and in section JUnit remove test configurations. Apply changes. After then try to run your tests. New configuration should be created automatically.

or:

  • Go to File --> Project Structure, select Modules, then select your proper module and go to the Paths tab.
    Check options:
    Radio button Use module compile output path should be selected.

    Output path should be inside your project. Also Test output path should be directory inside your project. For example it can look similarly:
    Output path: C:\path\to\your\module\yourModule \target\classes
    Test Output path: C:\path\to\your\module\yourModule \target\test-classes

    Exclude output paths should be deselected.