Zev Ross
Zev Ross

Reputation: 156

Junit test not working in VS Code -- Class not found exception

I'm trying to run Junit tests in vs code. They were working completely fine before but for some reason they're no longer working and I don't know why. I keep getting a class not found exception, even though the tests were working just fine and I didn't change any settings. I've tried everything but nothings seems to fix this error. Also, the CodeLens feature - the thing where the "run test" button appears underneath the @Test line - has never worked, I have never seen that button appear beneath @Test. Please help!

In case my code is the issue, here is my code:

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);
    }
}

And this is the error I get:

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

Thank you in advance!

Upvotes: 2

Views: 4365

Answers (1)

Zev Ross
Zev Ross

Reputation: 156

Issue resolved. Restarting my computer fixed it.

Upvotes: 1

Related Questions