首页 > 解决方案 > 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

这是我的文件路径设置,如果您需要知道

先感谢您!

标签: javavisual-studio-codejunit

解决方案


问题解决了。重新启动我的电脑修复了它。


推荐阅读