简体   繁体   中英

how to evaluate junit.xml using phing

I am using phing to build my CakePHP web application.

I want to have a phing target that goes along these lines:

  1. Run the test suite
  2. if there is even 1 failure, end the phing target
  3. if all okay, run the command "git commit -a"

For my test suite, I follow the CakePHP convention which uses PHPUnit

${cake} testsuite ${runinworkspaceapp} app AllTests --log-junit ${builddir}/logs/junit.xml

where

  • ${cake} simply means ${appdir}/Console/cake
  • ${runinworkspaceapp} means -app ${appdir}

I will generate a junit.xml file. Below is a snippet of the junit.xml

<testsuites>
  <testsuite name="All Tests" tests="44" assertions="373" failures="0" errors="0" time="4.634020">
    <testsuite name="All Model related class tests" tests="42" assertions="370" failures="0" errors="0" time="4.478717">

I suspect that I need to evaluate the junit.xml file in order to tell whether there is any error. I could be wrong and there is a better way.

How do I write the phing target?

Cake should exit with an exit code != 0 when at least one test failed, so using <exec> with checkreturn="true" should suffice.


junit.xml can be converted to HTML with a phing task (also see http://cweiske.de/tagebuch/visualizing-phpunit-runs.htm ):

<?xml version="1.0" encoding="utf-8"?>
<project name="testreport" default="gen-report" basedir=".">
 <target name="gen-report">
  <phpunitreport infile="log.junit.xml"
                 format="frames"
                 todir="html"
                 styledir="/usr/share/php/data/phing/etc/"
                 />
 </target>
</project>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM