我有两个相同的构建文件,看起来像这样
构建.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="Tryout" default="test1" basedir=".">
<property name="src" location="src"/>
<property name="build" location="bin"/>
<property name="junit" location="junit-4.10.jar"/>
<target name="compile" description="compile the source" >
<javac srcdir="${src}" destdir="${build}" debug="on">
<classpath location="junit-4.10.jar"/>
<classpath location="${build}"/>
</javac>
</target>
<target name="test1" depends="compile">
<junit printsummary="yes" fork="no" haltonfailure="no">
<classpath location="${build}"/>
<classpath location="junit-4.10.jar"/>
<formatter type="plain"/>
<test name="TestOne"/>
<test name="TestTwo"/>
</junit>
</target>
</project>
唯一的区别是在 Trial1 中的类在bin
,而在 Trial2 中的类在bin/one/two/three
并且所有的类都在包中one.two.three
。Trial1 运行良好,junit 测试运行并将结果打印到 txt 文件。Trial2 能够将源代码编译到适当的文件夹,但在 junit 执行时会失败。这是错误:
Testsuite: TestOne
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
Caused an ERROR
TestOne
java.lang.ClassNotFoundException: TestOne
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
这是我认为相关的调试的一部分
Class java.util.ArrayList loaded from parent loader (parentFirst)
Finding class org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner$3
Loaded from /usr/share/ant/lib/ant-junit.jar org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner$3.class
Finding class TestOne
Class java.lang.System loaded from parent loader (parentFirst)
Class java.lang.StringBuffer loaded from parent loader (parentFirst)
[junit] Running TestOne
Class org.apache.tools.ant.util.StringUtils loaded from parent loader (parentFirst)
Class org.apache.tools.ant.util.FileUtils loaded from parent loader (parentFirst)
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test TestOne FAILED
任何帮助我指出正确方向的帮助将不胜感激!感谢您的时间。