JUnit & Ant: How to show a detailed error message on the screen?

I am creating an Ant project that includes a unit test using JUnit.

The purpose of testing is as follows:

<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 only displays a summary of the test on the screen, for example:

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

Anyway, can I say JUnit or Ant to display the detailed result on the screen?

Also, if I want to write something in the unit test on the screen, how can I do this? I tried to insert System.out.println () into the test, but it does not display anything on the screen.

Many thanks.

+5
source share
5 answers

Set the flag showOutputto true.

What are you trying to do through Sop in the middle of the test?

+3
source

printsummary withOutAndErr, JUnit System.out System.err

+2

IMHO, you are solving the wrong problem.

The junit results are collected and sit "$ {test.reports.dir}" to be "noticed" by you. Ant has a task that can help you get an HTML report.

Imagine a goal to generate html from the collected data (these are XML files)

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

Also, if you want to print something on the screen, just use

<echo message="My message..." />
0
source
<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 file to generate reports as html files.

0
source

All Articles