1

I am trying to learn how to write a JUnit test.

here is all the content in Calculator.java.

public class Calculator {
    public int add(int a, int b) {
        return a + b;
    }
}

here is all the content in CalculatorTest.java.

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class CalculatorTest {
    private static Calculator calculator = new Calculator();

    @Before
    public void setUp() throws Exception {
    }

    @Test
    public void testAdd() {
        int actual_rs = calculator.add(1, 2);
        assertEquals(3, actual_rs);
    }

}

enter image description here

how to fix this error

java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:333)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadTestLoaderClass(RemoteTestRunner.java:380)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:370)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:365)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:309)
2
  • Since you are using Java 13, do you have Eclipse 2019-09 (4.13) with the Java 13 Support for Eclipse 2019-09 (4.13) plug-in? Please show the whole stack trace, not just the first lines. Please show also the import statements, to be sure JUnit 4 and 5 wasn't mixed (are you sure you want to learn JUnit with an outdated version?).
    – howlger
    Commented Dec 13, 2019 at 8:09
  • Thank you. with that plug-in and JUnit5, everything is OK. plz mv it to answer.
    – yigre20cn
    Commented Dec 14, 2019 at 1:29

1 Answer 1

1

Since you are using Java 13, makes sure you have Eclipse 2019-09 (4.13) with the Java 13 Support for Eclipse 2019-09 (4.13) plug-in (or Eclipse 2019-12 with built-in Java 13 support which will be released on 18 December 2019).

Make also sure, not to mix JUnit 4 and 5. For learning how to write a JUnit test, JUnit 5 is recommended instead of using the outdated previous version JUnit 4.

Not the answer you're looking for? Browse other questions tagged or ask your own question.