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

Same issue here using IDEA 15.0.6, and nothing helped except when I renamed the package the test class was in. Afterwards I renamed it back to its original name and it still worked, so the rename action might have cleared some cache.

查看更多
姐就是有狂的资本
3楼-- · 2020-01-27 10:26

In Android Studio 3.0 +, sometimes UI tests are somehow interpreted as unit tests and it doesn't ask for target deployment selection. You can go to Edit Configuration and mark it as an Integration test and it would start working

查看更多
虎瘦雄心在
4楼-- · 2020-01-27 10:26

Just click your mouse right button on the file in Projects windows and select

"Run YourTest".

Everything just starts OK now, probably because faulty run configuration is being rebuild anew.

查看更多
姐就是有狂的资本
5楼-- · 2020-01-27 10:27

I had a similar problem after starting a new IntelliJ project. I found that the "module compile output path" for my module was not properly specified. When I assigned the path in the module's "compile output path" to the proper location, the problem was solved. The compile output path is assigned in the Project settings. Under Modules, select the module involved and select the Paths tab...

Paths tab in the Project Settings | Modules dialog

screenshot

...I sent the compiler output to a folder named "output" that is present in the parent Project folder.

查看更多
ゆ 、 Hurt°
6楼-- · 2020-01-27 10:28

This might also happen, if your test folder has been imported as a separate module (a small square is shown on the folder icon in the project view).
Remove the module by selecting the test folder in the project view and press DEL.
Then start your test.
If a popup dialog appears with an error message, that no module is selected, specify your root module from the dropdown.

查看更多
可以哭但决不认输i
7楼-- · 2020-01-27 10:28

In my case, I had everything else in the right place, but I was working on a java library with kotlin. I just forgot to apply the plugin:

apply plugin: 'kotlin-android'

And now it's working as expected now.

查看更多
登录 后发表回答