2011-06-10 72 views
1

我想執行在/ test目錄的所有測試,而無需使用註釋,比如使用ANT運行jUnit - 如何在不使用@Suite的情況下執行所有測試?

@Suite.SuiteClasses(....) 

在過去我有一個單獨的類,它在呼喚着許多其他類測試它們。這種方法已不再可接受。

我有一個/測試目錄,在其下我有一些包,每個包含幾個測試。

在我目前的ANT劇本,我有:其次

<target name="test" depends="compileTest"> 
    <junit printsummary="yes" fork="no" haltonfailure="no"> 
     <classpath location="${bin}" /> 
     <formatter type="plain" /> 
    </junit> 
</target> 

<target name="compileTest" depends="compile" description="compile jUnit"> 
    <javac srcdir="${test}" destdir="${bin}" includeantruntime="true" /> 
</target> 

在過去,我已經

<test name="MyCollectionOfTests" /> 

我寧願不這樣做了。

我在想什麼?請指教。

回答

3

您可以使用嵌套的batchtest。例如:

<junit printsummary="on" 
     fork="on" 
     dir="${test.build}" 
     haltonfailure="false" 
     failureproperty="tests.failed" 
     showoutput="true"> 
    <classpath> 
    <path refid="tests.classpath"/> 
</classpath> 
<batchtest todir="${test.report}"> 
    <fileset dir="${test.gen}"> 
     <include name="**/Test*.java"/> 
    </fileset> 
    <fileset dir="${test.src}"> 
     <include name="**/Test*.java"/> 
     <exclude name="gen/**/*"/> 
    </fileset> 
    </batchtest> 
</junit> 

最簡單的形式,你可以簡單地添加一個嵌套:

<batchtest todir="report"> 
    <fileset dir="test"/> 
</batchtest> 

junit電話。

+0

這是一件很美的事情......謝謝 – JAM 2011-06-10 05:40:01

相關問題