# Junit not working giving error #
Tried testing basic add operation using Junit its showing this error on my mac
# AddTest.java #
import static org.junit.Assert.*;
import org.junit.Test;
public class AddTest {
@Test
public void Addtest() {
MyJUnitClass junit = new MyJUnitClass();
int result = junit.add(100, 200);
assertEquals(300, result);
}
}
# MyJunitClass #
public class MyJUnitClass {
public int add(int a, int b) {
return a+b;
}
public String conCat(String a, String b) {
return a+b;
}
}
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:332)
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)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:224)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:208)
Caused by: java.lang.ClassNotFoundException: org.junit.runner.manipulation.Filter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 8 more
这是我在运行时遇到的错误,我已将JUnit 4.jar文件库放置在buildpath中。我可以访问JUnit jar文件中的所有功能,但是当我运行JUnit测试时,会出现失败错误和控制台中的此消息。
答案 0 :(得分:0)
您应该尝试“添加库”,然后选择JUnit,而不是直接添加jar! 祝你好运:)