2012-03-05 9 views
5

Ho creato un progetto Ant che include un test unitario con JUnit.JUnit & Ant: come visualizzare un messaggio di errore dettagliato sullo schermo?

L'obiettivo del test è come:

<target name="test"> 
    <mkdir dir="target/test/reports"/> 
    <junit printsummary="yes" haltonfailure="yes"> 
     <classpath> 
      <pathelement location="${test.classes.dir}"/> 
      <pathelement location="${test.junit.jar}" /> 
      <pathelement path="${classes.dir}"/> 
      <pathelement path="${java.class.path}"/> 
     </classpath> 
     <formatter type="plain"/> 

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

Quando ho eseguito questo test, si mostrano sullo schermo solo la sintesi del test come:

Buildfile: F:\test\build.xml 

test: 
    [junit] Running com.mycompany.myproject.myTest 
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.013 sec 
    [junit] Running com.mycompany.myproject.myTest1 
    [junit] Tests run: 3, Failures: 1, Errors: 0, Time elapsed: 0.018 sec 

BUILD FAILED 
F:\test\build.xml:30: Test com.mycompany.myproject.myTest1 failed 

Total time: 1 second 

C'è qualche cosa che posso dire JUnit o Ant per visualizzare il risultato dettagliato sullo schermo?

Inoltre, se voglio scrivere qualcosa sullo schermo dell'unità sullo schermo, come posso farlo? Ho provato a inserire System.out.println() nel test ma non visualizza nulla sullo schermo.

Molte grazie.

risposta

3

Impostare il flag showOutput su true.

Cosa stai cercando di ottenere tramite la S.o.p nel bel mezzo di un test?

2

cambiamento printsummary valore withOutAndErr, che causerà JUnit per stampare System.out e il testo System.err

1

IMHO, si sta risolvendo il problema sbagliato.

I risultati di junit vengono raccolti e posti "$ {test.reports.dir}" per essere "visti" da voi. Formica ha compito che potrebbe aiutare a getting an HTML report

introduzione di un obiettivo di generare codice HTML dai dati raccolti (sono file XML)

<junitreport todir="./reports"> 
    <fileset dir="${test.reports.dir}"> 
    <include name="TEST-*.xml"/> 
    </fileset> 
    <report format="frames" todir="./report/html"/> 
</junitreport> 
0

Inoltre, se si desidera stampare qualcosa sullo schermo, basta usare

<echo message="My message..." /> 
0
<batchtest fork="yes" todir="${junit.report.dir}"> 
    <formatter type="xml" /> 
     <fileset dir="${application.build.stage.java.class.dir}"> 
     <include name="**/*Test.class" /> 
</fileset> 
</batchtest> 

È possibile utilizzare questo nel vostro build.xml per generare i report come file html.

Problemi correlati