Reputation: 6292
I put up an Ant project which includes a unit test using JUnit.
The test target is as:
<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>
When I run this test, it show on the screen only the summary of the test like:
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
Is there anyway I can tell JUnit or Ant to display the detailed result on the screen?
Also, if I want to write something in the Unit test to the screen, how can I do this? I tried to insert System.out.println() in the test but it does not display anything on the screen.
Many thanks.
Upvotes: 5
Views: 6880
Reputation: 939
<batchtest fork="yes" todir="${junit.report.dir}">
<formatter type="xml" />
<fileset dir="${application.build.stage.java.class.dir}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
You can use this in your build.xml to generate the reports as html files.
Upvotes: 0
Reputation: 1569
Also, if you want to print something to the screen, just use
<echo message="My message..." />
Upvotes: 0
Reputation: 18459
IMHO, you are solving the wrong problem.
The junit results are collected and sitting "${test.reports.dir}" to be 'seen' by you. Ant has task that could help you in getting an HTML report
Introduce a target to generate html from the collected data (they are XML files)
<junitreport todir="./reports">
<fileset dir="${test.reports.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="./report/html"/>
</junitreport>
Upvotes: 2
Reputation: 11090
change printsummary
value to withOutAndErr
, that will cause JUnit to print System.out and System.err text
Upvotes: 2
Reputation: 160171
Set the showOutput
flag to true.
What are you trying to accomplish via the S.o.p in the middle of a test?
Upvotes: 3