java - Junit 测试在 VS Code 中不起作用——找不到类异常
问题描述
我正在尝试在 vs 代码中运行 Junit 测试。他们以前工作得很好,但由于某种原因他们不再工作了,我不知道为什么。即使测试运行良好并且我没有更改任何设置,我也不断收到未找到类的异常。我已经尝试了一切,但似乎没有解决这个错误。此外,CodeLens 功能——“运行测试”按钮出现在该@Test
行下方的东西——从未起作用,我从未见过该按钮出现在@Test
. 请帮忙!
如果我的代码是问题,这是我的代码:
package test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import main.*;
/**
* This class will contain my test for the RaceCar constructor.
* @author zevross
*/
public class RaceCarConstructorTest {
/**
* This test tests the constructor of our RaceCar class. We will test the
* empty constructor, both extremes, and an arbitrary middle value. If
* the car's speed and strength variables are what they should be, it
* will pass the test!
*/
@Test
public void testRaceCar() {
// instantiating racecars
RaceCar racecar1 = new RaceCar();
RaceCar racecar2 = new RaceCar(-1, -1);
RaceCar racecar3 = new RaceCar(100, 100);
RaceCar racecar4 = new RaceCar(45, 3);
// constructor testing
assertEquals(40, racecar1.speed);
assertEquals(3, racecar1.strength);
assertEquals(30, racecar2.speed);
assertEquals(2, racecar2.strength);
assertEquals(55, racecar3.speed);
assertEquals(4, racecar3.strength);
assertEquals(45, racecar4.speed);
assertEquals(3, racecar4.strength);
}
}
这是我得到的错误:
Class not found test.RaceCarConstructorTest
java.lang.ClassNotFoundException: test.RaceCarConstructorTest
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
// some more error locations follow after this but I assume they're not important
先感谢您!
解决方案
问题解决了。重新启动我的电脑修复了它。
推荐阅读
- angular - 如何组合 2 个不同的数组列表 [Angular,typescript]
- angular - 角度升级 9 到 10
- amazon-web-services - 如何使用 Kinesis Video Streams 和 WebRTC 中的帧对 EC2 实例中托管的 ML 模型进行预测?
- python - 我在 Tkinter 中作为按钮添加的图像不可见,文本版本可见
- css - 由firefox而不是chrome反转的css旋转动画
- angular - ngModel 在 ng-For 中使用时覆盖之前的值
- java - 在 Swagger + Spring boot 中隐藏参数
- c++ - 如何在 .cpp 文件中函数的返回类型(签名)中使用在头文件中定义的别名?
- python - 如何为 python 3.7 安装 ctypes 模块以与 VSCode 调试器一起使用
- javascript - Promise 和 async/await 的区别