【发布时间】:2020-11-01 16:17:10
【问题描述】:
我正在尝试在 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
Here is my file path setup, if you need to know
提前谢谢你!
【问题讨论】:
-
你是如何运行测试的?
-
我使用了 Java 测试运行器扩展。现在问题已经解决了,只需要重新启动即可。
标签: java visual-studio-code junit