我刚开始读大学的计算机科学课程,我在使用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 3.0 +中,UI测试有时会被解释为单元测试,它不要求目标部署选择。您可以转到Edit Configuration并将其标记为集成测试,它将开始工作

其他回答

当你的模块-和/或项目-jdk没有正确配置时,也会发生这种情况。

在开始一个新的IntelliJ项目后,我也遇到了类似的问题。我发现我的模块的“模块编译输出路径”没有正确指定。当我将模块的“编译输出路径”中的路径分配到适当的位置时,问题就解决了。编译输出路径在Project设置中分配。在“模块”下,选择所涉及的模块并选择“路径”选项卡…

项目设置|模块对话框中的路径选项卡

...我将编译器输出发送到父项目文件夹中名为“output”的文件夹中。

在Intellij中遵循以下步骤(为了更好地理解,有截图):

转到文件—>项目结构

导航到模块,现在选择Junit测试文件所在的模块,并选择“使用模块编译输出路径”单选按钮。 提到各自的类文件夹路径,类似于所附的屏幕截图。

请申请和好的。 这对我很管用!

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

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

删除和重新创建运行配置也有帮助。