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.
Set the showOutput
flag to true.
What are you trying to accomplish via the S.o.p in the middle of a test?
change printsummary
value to withOutAndErr
, that will cause JUnit to print System.out and System.err text
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With