我已经在Ubuntu 11.04上安装了JUnit
sudo apt-get install junit
然后创建一个测试文件,如:
import org.junit.*;
public class TestBasicLinkedList {
@Test public void testCanAdd(String[] args) {
BasicLinkedList<Integer> list = new BasicLinkedList();
list.add(new BasicListNode<Integer>(1));
assertTrue(list.size() == 1);
assertTrue(list.getFirst().getElement().equals(1));
}
}
然后尝试在终端中运行
java org.junit.runner.JUnitCore TestBasicLinkedList.java
得到了:
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/runner/JUnitCore
Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore
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:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.junit.runner.JUnitCore. Program will exit.
如何使用JUnit?有比长命令更好的短使用方法java org.junit.runner.JUnitCore TestBasicLinkedList.java
吗?也许像junit *.Tests.java
?
/usr/share/java/junit.jar
链接到最新的junit3版本,同时/usr/share/java/junit4.jar
链接到最新的junit4版本。