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:42

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

Worked for me :-)

查看更多
欢心
3楼-- · 2020-01-27 10:42

For me it was because my project was being compiled into a directory outside of the project. In paths the output paths were \production\project_name and \test\project_name which was putting them in C:\production\project_name. Changing them to the full path of the project allowed my tests to access the class files.

查看更多
劳资没心,怎么记你
4楼-- · 2020-01-27 10:43

Was getting same error. My device was not connected to android studio. When I connected to studio. It works. This solves my problem.

查看更多
成全新的幸福
5楼-- · 2020-01-27 10:44

I had the same issue (Android Studio 3.2 Canary 4) and I tried most of suggestions described in other answers - without any success. Note this happened after I moved the file from test to androidTest folder. It was still shown in run configurations as test instead of instrumented test.

I finally end up with creating a new file:

  1. Create new instrumented test class with different name.
  2. Copy all the code from your class.
  3. Run it.
  4. Delete the old class.
  5. Rename new class to desired name.
查看更多
够拽才男人
6楼-- · 2020-01-27 10:45

This can happen (at least once for me ;) after installing the new version of IntelliJ and the IntelliJ plugins have not yet updated.

You may have to manually do the Check for updates… from IntelliJ Help menu.

查看更多
The star\"
7楼-- · 2020-01-27 10:46

In my case, IntelliJ didn't compile the test sources for a strange reason. I simply modified the build configuration and added the maven goal clean test-compile in the Before launch section

查看更多
登录 后发表回答