问题描述
好吧,我和jUnit一样,还很陌生,并且很难使它工作.我已经搜索了论坛,但是提供了答案;我只是不明白.如果外面有人可以帮助我,我将不胜感激.
Ok, I am like other and new to jUnit and having a difficult time trying to get it working. I have searched the forum but the answers provided; I am just not getting. If anyone out there could lend me a hand I would greatly appreciate it.
让我提供基本信息:操作系统:mac OS X.6
Let me provide the basics:OS: mac OS X.6
export JUNIT_HOME="/Developer/junit/junit4.8.1"
export CVSROOT="/opt/cvsroot"
export PATH="/usr/local/bin:/usr/local/sbin:/usr/localmysql/bin:/opt/PalmSDK/Current/bin/:/usr/local/mysql/bin:$PATH:$JUNIT_HOME:$CVSROOT"
export CLASSPATH="$CLASSPATH:$JUNIT_HOME/junit-4.8.1.jar:$JUNIT_HOME"
我可以从Java文件中编译测试类,但是当我尝试随后运行测试时
I can compile a test class from a java file, however when I try to then run the test
java org.junit.runner.JUnitCore MyTest.class
我得到以下信息:
JUnit version 4.8.1
Could not find class: MyTest.class
Time: 0.001
OK (0 tests)
现在我进入了位于文件系统中某个位置的MyTest.class
目录,我尝试将源文件夹移动到junit
文件夹和junit/junit4.8.1
文件夹,结果相同.我什至无法运行junit随附的测试.
Now I have been in the directory with the MyTest.class
which is just somewhere in my file system, I tried moving the source folder to the junit
folder and the junit/junit4.8.1
folder and the same result. I cannot even run the tests that came with junit.
推荐答案
MyTest
是否真的在默认软件包中?如果不是,那么您需要给出整个程序包限定的名称.换句话说,如果MyClass有一条语句
Is MyTest
really in the default package? If not, then you need to give the entire package-qualified name. In other words, if MyClass has a statement
package com.myself;
并居住在
/myproject/src/com/myself/MyClass.java
然后您编译成
/myproject/classes
然后/myproject/classes
必须位于您的CLASSPATH
上并且您必须
then /myproject/classes
must be on your CLASSPATH
and you must
java org.junit.runner.JUnitCore com.myself.MyTest
想一想,我现在看到您正在将.class
附加到类名上,所以即使它在默认程序包中,您也应该说
Come to think of it, I see now that you're appending .class
to the class name, so even if it's in the default package, you should just say
java org.junit.runner.JUnitCore MyTest
这篇关于JUnit:4.8.1“找不到类"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!