Z
Z
zencd2010-12-04 00:06:34
Apache Ant
zencd, 2010-12-04 00:06:34

How to run all junit tests with Ant and get the correct exit code at the same time?

[junit haltonfailure = false] - in the end Ant writes like "BUILD SUCCESSFUL" - it's lying, in fact.

[junit haltonfailure = true] - no longer says “successful”, but the process stops at the first failed test.

How to get the correct status and run all the tests?

// Ant 1.8

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pyatigil, 2010-12-26
@pyatigil

well, in general, you can get the result from the junit task in the attribute: [junit… failureproperty=testsfailed]
and then [fail message="Tests failed." unless="testsfailed"/]
although it's strange that it has to be so hard to do =(

A
Alexey Kiselev, 2013-11-19
@alexeykiselev

<target name="run-test" depends="init-test, compile-test" unless="option.skiptest">
    <mkdir dir="${test.xml}" />

    <junit 
      haltonfailure="off"
      haltonerror="off"
      errorproperty="test.failed"
      failureproperty="test.failed"
      showoutput="no"
      printsummary="yes"
      includeantruntime="yes"
      dir="${test.build}"
      fork="true">
      <classpath>
        <path refid="test.classpath" />
      </classpath>
      <formatter type="xml"/>
      <batchtest todir="${test.xml}">
        <fileset refid="test.fileset" />
      </batchtest>
    </junit>
  </target>

  <target name="test" depends="run-test" unless="option.skiptest" description="Run unit tests">
    <fail if="test.failed"
      message="At least one test has failed. See logs (in ${test.xml}) for details (use the target test-report to run the test with a report)" />
  </target>

  <target name="test-report" depends="run-test" unless="option.skiptest" description="Run the test with report">
    <junitreport todir="${test.xml}">
      <fileset dir="${test.xml}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="noframes" todir="${reports}">
      </report>
    </junitreport>
    <fail if="test.failed"
      message="At least one test has failed. See logs (in ${test.xml}) or report (in ${reports})" />
  </target>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question