我刚开始读大学的计算机科学课程,我在使用IntelliJ时遇到了一些问题。当我试图运行单元测试时,我得到了消息

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

我还在屏幕左侧看到一条标题为“未找到测试”的消息。我的测试代码如下:

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);
    }
}

我的项目代码在这里:

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;
}

}

我怎样才能让我的测试正常工作?我使用的是IntelliJ IDEA CE的最新版本。


当前回答

得到相同的错误。我的设备没有连接到android studio。当我连接到工作室。它的工作原理。这解决了我的问题。

其他回答

只需在项目窗口中的文件上单击鼠标右键并选择

运行您的测试。

现在一切开始正常,可能是因为错误的运行配置正在重新构建。

我解决这个问题的方法是使用文件夹名称和路径。

由于某些原因,我的测试丢失了/java/文件夹,IntelliJ不喜欢这样。

所以从 . . /测试/ com/.。 来 . . /测试/ java / com/.。

这是好的

对我来说,这个项目是在项目之外编译的。我只是改变了路径。 更改路径(我使用mac)。

进入文件—>项目结构 进入左边的模块。 选择路径,选择单选按钮(使用模块编译输出路径) 提供输出路径和测试输出路径,这是在你的项目 取消选择“排除输出路径”。 进入文件——>单击“无效缓存”并重新启动

在我的情况下,有一个问题的测试名称:)。

如果名字是: dummyNameTest则在找到的地方不进行测试,但以防万一 一切正常

当我从Maven导入一些jar时,我遇到了同样的问题,随后导致了空测试套件错误。

在我的例子中,这是因为maven重置了模块文件。我通过清除默认配置解决了这个问题:

用shift-ctrl-alt-s快捷键打开项目结构

查看Modules > Sources并填充Sources包或测试package。