2011-01-21 18 views
5

Ho una directory con una serie di test JUnit nel mio progetto. Finora ho usato un target separato per ogni unit test. Ad esempio:Esegui tutti i test unitari con Ant builder

<target name="MyTest"> 
     <mkdir dir="${junit.output.dir}"/> 
     <junit fork="yes" printsummary="withOutAndErr"> 
      <formatter type="xml"/> 
      <test name="tests.MyTest" todir="${junit.output.dir}"/> 
      <classpath refid="MyProject.classpath"/> 
     </junit> 
    </target> 

Questo metodo mi richiede di cambiare il file di build ogni volta che aggiungo un test di unità.
Voglio riuscire a eseguire tutti i test di unità nel progetto con un singolo target di build Ant.
È possibile fare?

risposta

9

Sì lo è, è necessario guardare il cartellino del set di file, per esempio:

<junit printsummary="yes" haltonfailure="yes"> 
    <classpath> 
    <pathelement location="${build.tests}"/> 
    <pathelement path="${MyProject.classpath}"/> 
    </classpath> 

    <formatter type="xml"/> 

    <batchtest fork="yes" todir="${reports.tests}"> 
    <fileset dir="${src.tests}"> 
     <include name="**/*Test*.java"/> 
     <exclude name="**/AllTests.java"/> 
    </fileset> 
    </batchtest> 
</junit> 

La parte importante è l'uso di set di file e un glob/modello jolly per abbinare i nomi dei test. docs complete sul compito JUnit con esempi qui:

http://ant.apache.org/manual/Tasks/junit.html

3

Yep! Lo facciamo usando un batchtest di comando ant. Appare come questa

 <batchtest todir="${junit.report.dir}"> 
      <fileset dir="${basedir}\test\unit"> 
       <include name="**/*Test.java" /> 
      </fileset> 
     </batchtest> 

Google, dovrebbe ordinare fuori