用Ant集成JUnit测试失败与ClassNotFoundException异常 [英] Junit test integrated with Ant Failed with ClassNotFoundException
问题描述
我有我的项目,与Eclipse正确运行JUnit测试。
I have JUnit tests on my project that run correctly with Eclipse.
所以,现在我尝试这些测试与Ant任务结合起来。为了让我做以下ant脚本:
So, now I try to integrate these tests with an ant task. To make that I make the following ant script :
<path id="classpath-test">
<pathelement path="." />
<pathelement path="${classes.home}" />
<fileset dir="${lib.home}" includes="*.jar" />
<fileset dir="${libtest.home}" includes="*.jar" />
</path>
<target name="compile" ... > // compiles src code of the project
<target name="compile-tests" depends="compile">
<javac srcdir="${test.home}"
destdir="${testclasses.home}"
target="1.5"
source="1.5"
debug="true"
>
<classpath refid="classpath-test" />
</javac>
<copy todir="${testclasses.home}">
<fileset dir="${test.home}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="unit-test" depends="compile-tests">
<junit printsummary="false" fork="off" haltonfailure="true">
<classpath refid="classpath-test" />
<formatter type="brief" usefile="false" />
<test name="com.test.MyTest" />
<!--<batchtest todir="${reports.dir}" >
<fileset dir="${testclasses.home}" >
<exclude name="**/AllTests*"/>
<include name="**/*Test.class" />
</fileset>
</batchtest>-->
</junit>
</target>
目录$ {} libtest.hom包含的junit-4.8.1.jar和hamcrest核心-1.1.jar。
The directory ${libtest.hom} contains junit-4.8.1.jar and hamcrest-core-1.1.jar.
当我启动以下命令:ant单元测试时,MyTest的执行失败,出现以下的输出:
When I launch the following command : ant unit-test, the execution of the MyTest fails with the following output :
unit-test:
[junit] Testsuite: com.test.MyTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit]
[junit] Null Test: Caused an ERROR
[junit] com.test.MyTest
[junit] java.lang.ClassNotFoundException: com.test.MyTest
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[junit] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:247)
[junit]
[junit]
这是非常奇怪,因为com.test.MyTest远在classpath中指出在Ant脚本我的任务的JUnit。有人将不得不和想法来解决这个问题?
It's very strange because com.test.MyTest is well in the classpath pointed for my task junit in ant script. Someone would have and idea to solve this problem ?
感谢您的帮助。
维尔托德。
推荐答案
的 $ {testclasses.home}
目录是无处关于 A类路径&LT; JUnit的方式&gt;
任务
我觉得这是对类文件 com.test.MyTest
生活。
I think this is where class file for com.test.MyTest
lives.
下面是修改单元测试目标:
Here is modified unit-test target:
<target name="unit-test" depends="compile-tests">
<junit printsummary="false" fork="off" haltonfailure="true">
<classpath>
<path refid="classpath-test"/>
<fileset dir="${testclasses.home}"/>
</classpath>
<formatter type="brief" usefile="false" />
<test name="com.test.MyTest" />
<!--<batchtest todir="${reports.dir}" >
<fileset dir="${testclasses.home}" >
<exclude name="**/AllTests*"/>
<include name="**/*Test.class" />
</fileset>
</batchtest>-->
</junit>
</target>
这篇关于用Ant集成JUnit测试失败与ClassNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!