Class Not Found: Empty Test Suite in IntelliJ

2020-01-27 09:56发布

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.

30条回答
手持菜刀,她持情操
2楼-- · 2020-01-27 10:24

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.
查看更多
欢心
3楼-- · 2020-01-27 10:24

So, my issue here was with folder names. I had called my code folder Classes 2016/2017, which IntelliJ didn't like. Simply remove the slash (or other offending character in path), re-import the project, and you'll be good to go!

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2020-01-27 10:24

Interestingly, I've faced this issue many times due to different reasons. For e.g. Invalidating cache and restarting has helped as well.

Last I fixed it by correcting my output path in File -> Project Structure -> Project -> Project Compiler Output to : absolute_path_of_package/out

for e.g. : /Users/random-guy/myWorkspace/src/DummyProject/out

查看更多
我只想做你的唯一
5楼-- · 2020-01-27 10:24

For me the project was compiled outside the project. I just change the path. For changing the path (i'm using mac).

  • Go to File --> Project Structure
  • Go to Module on left side.
  • Select Paths, select radio button(use module compile output path)
  • Provide output path and Test output path which is inside your project
  • Deselect Exclude output paths.
  • Go to File --> Click on Invalidate Cache and restart
查看更多
女痞
6楼-- · 2020-01-27 10:24

I tried all solutions but none of them helped. At the end i run test in debug mode and.... it started to work. Maybe some maven's cache was cleared up. It is difficult to say. It works. Try mvn test -X

查看更多
狗以群分
7楼-- · 2020-01-27 10:25

I went to

File -> Invalidate Caches/Restart...

and then it worked for me.

查看更多
登录 后发表回答