找不到类:IntelliJ 中的空测试套件

新手上路,请多包涵

我刚刚在我的大学开始计算机科学课程,我遇到了一些 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。

原文由 arnbobo 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 439
2 个回答

所以,我的问题是文件夹名称。我调用了 IntelliJ 不喜欢的代码文件夹 Classes 2016/2017。只需删除斜杠(或路径中的其他违规字符),重新导入项目,您就可以开始了!

原文由 arnbobo 发布,翻译遵循 CC BY-SA 3.0 许可协议

有同样的信息。我不得不删除运行/调试配置。

就我而言,我之前将单元测试作为本地测试运行。之后,我将测试移至 androidTest 包并尝试再次运行它。 Android Studio 记住了上次运行的配置,因此它尝试再次运行它作为产生相同错误的本地单元测试。

删除配置并再次运行测试后,它生成了一个新配置并运行。

在此处输入图像描述

原文由 com2ghz 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题