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

I had the same question when I import some jar from Maven, and subsequently, cause the empty-test-suite error.

In my case, it was because the maven resetting the module files. Which I resolved by clearing my default configuration:

  1. Open Project structure with shift-ctrl-alt-s shortcut

Screenshot of PModules Sources

  1. Look at the Modules > Sources and fill the Sources package or test Package.
查看更多
SAY GOODBYE
3楼-- · 2020-01-27 10:32

In my case there was a problem with test name :).

If name was: dummyNameTest then get no tests where found, but in case testDummyName everything was ok

查看更多
Ridiculous、
4楼-- · 2020-01-27 10:38

It's probably because the folder is not set as test source, which can be done via Module Settings > Modules.

查看更多
孤傲高冷的网名
5楼-- · 2020-01-27 10:40

Does your test require an Android device (emulator or hardware)?
If so, it's called an "instrumented test" and resides in "module-name/src/androidTest/java/".
If not, it's called a "local unit test" and resides in "module-name/src/test/java"

https://developer.android.com/training/testing/start/index.html

I got the same error because I had written a local unit test, but it was placed in the folder for instrumented tests. Moving the local unit test to the "src/test/java" folder fixed it for me.

查看更多
smile是对你的礼貌
6楼-- · 2020-01-27 10:41

Reimport project or module can solve the issue. I made this issue by renaming package name when developing. But the out path and test output path is the old path. So intellij can't find the class from the old path. So the easiest way is correcting the out path and test output path.

Intellij module setting

查看更多
Deceive 欺骗
7楼-- · 2020-01-27 10:41

If the project has compilation issue then tests might not run. So firstly build project as Build -> Build Project. After successful compilation re-run the test.

If nothing works out then just close the project window and delete project and re-import as Gradle/Maven project which will set everything for you by overriding the existing IntelliJ created files.This will remove invalid cache created.

You can also just invalidate the cache.

File -> Invalidate Caches/Restart

查看更多
登录 后发表回答