0
我有這個樣子還有一個螞蟻/ JUnit的ClassNotFoundException的
的build.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
任何幫助點我在正確的方向將不勝感激!感謝您的時間。
哇非常感謝你的好先生 – Steve 2013-03-14 08:43:44