我正在使用junit ant目标来运行junit。当我单独运行Junit文件时,Junit运行正常。当我尝试使用ant脚本时,junit测试用例没有执行。它显示错误为,
Running x.SimpleTest
[junit] Testsuite: x.SimpleTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Caused an ERROR
[junit] x.SimpleTest
[junit] java.lang.ClassNotFoundException: x.SimpleTest
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
[junit] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:247)
[junit] at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
[junit] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
[junit] Test x.SimpleTest FAILED
但是类在类路径中。请帮我调试一下。
我的构建文件是,
<property file="build.properties" />
<path id="libirary">
<fileset dir="${lib}">
<include name="**.*jar" />
</fileset>
</path>
<path id="applicationClassPath">
<path id="classpath1" refid="libirary" />
<pathelement id="classpath2" location="${build.classes.dir}" />
</path>
<path id="application.classpath">
<pathelement path="${java.class.path}" />
</path>
<path id="class.path">
<fileset dir="${build.classes.dir}" />
</path>
<property name="classPath" refid="applicationClassPath" />
<target name="clean">
<delete dir="${build.classes.dir}" />
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<target name="init" depends="clean">
<mkdir dir="${build.classes.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<target name="compile" depends="init">
<javac encoding="ISO-8859-1" destdir="${build.classes.dir}" srcdir="${src.dir}" debug="true" verbose="false">
<classpath>
<path refid="libirary" />
</classpath>
</javac>
</target>
<target name="jar" depends="compile">
<jar destfile="${dist.dir}/${jar.filename}.jar">
<fileset dir="${build.classes.dir}" />
<zipfileset dir="${lib}" includes="**/*.jar" />
<manifest>
<attribute name="Main-Class" value="${main.file.name}" />
</manifest>
</jar>
</target>
<target name="junit" depends="compile">
<echo message="classpath= ${classPath}" />
<junit printsummary="yes" description="true" filtertrace="yes" showoutput="yes">
<formatter type="plain" usefile="false" />
<classpath>
<path refid="applicationClassPath" />
</classpath>
<test name="x.SimpleTest" filtertrace="true">
</test>
</junit>
</target>
现在已解决。这是由于类路径错误。感谢大家的回复。