2013-02-13 68 views
1

我有這樣和正常工作:螞蟻 - 設置CLASSPATH不起作用對於批量測試

<target name="runjunit"> 
    <junit> 
     <classpath> 
      <pathelement path="${build}"/> 
      <fileset dir="lib"> 
       <include name="*.jar"/> 
      </fileset> 
     </classpath> 
     <test name="com.xyzcompany.abcproject.test.junit.CalculatorTest"/> 
     <formatter type="brief" usefile="false"/> 
    </junit> 
</target> 

不過,我有多個測試。所以我這樣做:

<target name="runjunit"> 
    <junit> 
     <classpath> 
      <pathelement path="${build}"/> <---- this doesn't seem to work anymore 
      <fileset dir="lib"> 
       <include name="*.jar"/> 
      </fileset> 
     </classpath> 
     <batchtest> 
      <fileset dir="com/xyzcompany/abcproject/test/junit"> 
       <include name="**/*.*"/> 
      </fileset> 
     </batchtest> 
     <formatter type="brief" usefile="false"/> 
    </junit> 
</target> 

但是,告訴我的目錄不存在:

C:\Users\me\Desktop\repository\mainproj\trunk\com\xyzcompany\abcproject\test\junit does not exist.

上面的應該是:

C:\Users\me\Desktop\repository\mainproj\trunk\build\com\xyzcompany\abcproject\test\junit

正如你看到的,classpath中的pathelement會在單個測試中設置trunk/build/com,但不在batchtest中。

目錄和軟件包名稱模糊隱私。

任何想法如何改變batchtest,使classpath中的pathelement實際上起作用?謝謝!

編輯:

這不起作用:

<batchtest> 
    <fileset dir="${build}/com/xyzcompany/abcproject/test/junit"> 
     <include name="**/*.*" /> 
    </fileset> 
</batchtest> 

它給我:

java.lang.ClassNotFoundException: CalculatorTest

將其設置爲<fileset dir="${build}/com/xyzcompany/abcproject/test/junit">沒有任何意義,因爲沒有按類不知道它正在建設中。因此,設置類路徑是正確的選項,但不適用於<batchtest>

編輯2:

現在,我真的想它,它有一定道理做<fileset dir="${build}/com/xyzcompany/abcproject/test/junit">。但是,當它爲junit旋轉java時,它不會從${build}類路徑運行junit。

編輯3:

<batchtest> 
    <fileset dir="${build}"> 
     <include name="com/xyzcopmany/abcproject/test/junit/*"/> 
    </fileset> 
</batchtest> 

最終的答案。螞蟻應該真的有更好的文檔。這是一個複雜的產品...

回答

3

設置

<fileset dir="com/xyzcompany/abcproject/test/junit"> 

<batchtest> 
    <fileset dir="${buildTests}"> 
     <include name="**/*Test*.class"/> 
    </fileset> 
</batchtest> 

請勿在$ {buildTests}中包含com/xyzcompany/abcproject/test/junit部分。

+0

請參閱我的編輯。 – jn1kk 2013-02-13 17:43:37

+0

好的,我認爲你不應該包含com/xyzcompany/abcproject/test/junit部分。只需將您的測試編譯到某個目錄幷包含此目錄的路徑 – 2013-02-13 17:58:18

+0

謝謝,您是最接近我的人。想要確切答案的人,請參閱我最後的編輯。 – jn1kk 2013-02-13 18:09:57

0

如果你想從${build}目錄拿起你的批量測試中的文件,你應該告訴如此

<batchtest> 
     <fileset dir="${build}/com/xyzcompany/abcproject/test/junit"> 
      <include name="**/*"/> 
     </fileset> 
    </batchtest> 
+0

請參閱我的編輯。 – jn1kk 2013-02-13 17:44:29