JUnit无法找到我的班级

时间:2015-03-05 12:59:55

标签: java command-line junit

当我运行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

1 个答案:

答案 0 :(得分:2)

  

尝试了java -cp $ JUNITPATH org.junit.runner.JUnitCore   TestCalculatorWithMethod最后没有.class? - 大卫   华莱士

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