gpt4 book ai didi

java - JUnit 无法找到我的类

转载 作者:行者123 更新时间:2023-11-30 03:31:36 25 4
gpt4 key购买 nike

当我运行 JUnit 时,我收到一条错误消息,指出它无法找到我正在通过的测试。但是,因为该类位于我的工作目录中,而我的工作目录位于我的类路径中,所以我不确定为什么。谁能指出我正确的方向吗?

grader $  echo $JUNITPATH
/users5/cse/dfischer/lib/junit.jar:/users5/cse/dfischer/lib/hamcrest-core-1.3.jar:.
grader $ ls -l TestCalculatorWithMethod.class
-rw-r--r-- 1 dfischer cseugrad 1625 Mar 2 20:11 TestCalculatorWithMethod.class
grader $ java -cp $JUNITPATH org.junit.runner.JUnitCore TestCalculatorWithMethod.class
JUnit version 4.12
.E
Time: 0.001
There was 1 failure:
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [TestCalculatorWithMethod.class]
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:102)
at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)
at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: TestCalculatorWithMethod.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.junit.internal.Classes.getClass(Classes.java:16)
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:100)
... 4 more

FAILURES!!!
Tests run: 1, Failures: 1

最佳答案

Tried java -cp $JUNITPATH org.junit.runner.JUnitCore TestCalculatorWithMethod without the .class at the end? – David Wallace

问题是传入 TestCalculatorWithMethod.class 而不是 TestCalculatorWithMethod。

关于java - JUnit 无法找到我的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28878465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com