root@ubuntu:/home/dj/workspace/TestProject# ant test Buildfile: /home/dj/workspace/TestProject/build.xml test: [junit] Testsuite: TestProject [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec [junit] [junit] Caused an ERROR [junit] TestProject [junit] java.lang.ClassNotFoundException: TestProject [junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:202) [junit] at java.security.AccessController.doPrivileged(Native Method) [junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:190) [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:306) [junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:247) [junit] at java.lang.Class.forName0(Native Method) [junit] at java.lang.Class.forName(Class.java:169) [junit] BUILD FAILED /home/dj/workspace/TestProject/build.xml:17: Test TestProject failed Total time: 0 seconds
<project name="TestProject" basedir="." default="" >
<property name="src" value="./src" />
<property name="lib" value="./lib" />
<property name="classes" value="./classes" />
<property name="ant.project.name" value="com.megacorp.projx.util" />
<path id="test.classpath">
<pathelement location="${classes}" />
<pathelement location="usr/junit.jar" />
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="test">
<junit fork="yes" haltonfailure="yes">
<test name="${ant.project.name}" />
<formatter type="plain" usefile="false" />
<classpath refid="test.classpath" />
</junit>
</target>
答案 0 :(得分:0)
这是错误的:
<test name="${ant.project.name}" />
在这里,您应该设置要测试的junit-class的名称,而不是ant项目的名称。
E.g:
<test name="myorg.MyTest" />
<强>链接:强>
Documentation for junit task:查看底部的示例