Using PHPUnit with Hudson
The problem with undocumented standards is that they tend not to be very standardised. The XML format used by Ant’s JUnitReport task has been adopted, extended and bastardised by several different testing tools to the extent that there are at least half a dozen different dialects currently in use. This creates a problem for tools like Hudson that try to parse this inconsistent output. Currently Hudson works correctly with the XML from JUnit, TestNG (including ReportNG) and some other tools but it doesn’t recognise the output from Google Test or PHPUnit.
I was going to make the necessary changes to Hudson so that it accepts the PHPUnit and Google Test variants but I had some problems getting Hudson to build (yay Maven!). I may return to implementing this fix later but for now I’ve used a quick and dirty hack that massages PHPUnit’s output into a form more acceptable to Hudson. Since I’m invoking PHPUnit from a shell script, I can use sed to make the necessary modifications. In PHPUnit’s case, I just need to eliminate the nesting of <testsuite> tags, which can be done by deleting the third and penultimate lines of the XML file:
# Tweak the test result XML to make it acceptable to Hudson. lines=`wc -l test-results/results.xml|awk '{print $1}'` end=`expr $lines - 1` sed -i "$end d;3d" test-results/results.xml

on April 1st, 2009 at 9:43 pm
Hello! I saw you respond to my stack overflow post (http://stackoverflow.com/questions/518083/how-might-i-integrate-phpunit-with-hudson-ci) and link here, and I thought I would try this out. Unfortunately I still get the “None of the test reports contained any result” error. You mention Hudson can’t handle nested testsuite tags, and if so then it makes sense because my phpunit result XML file is many levels deep:
<testsuites
<testsuite
<testsuite
<testsuite
<testcase
So I suppose in my case just removing the first level wasn’t enough. I’d really need something to recursively remove them and perhaps adjust the classnames appropriately.
If you have any hints here that would be greatly appreciated! I’d also encourage you take another shot at supporting things like this in Hudson as it would help people like myself out as well
on April 2nd, 2009 at 6:49 pm
MIke, I was afraid that might be a problem. It’s the first time I’ve used PHPUnit, so it worked for me but I wasn’t sure it would work in general.
I’ll take another look at enhancing Hudson at the weekend if I get a chance.
on April 22nd, 2009 at 10:29 am
Thanks for your solution. I use for Hudson phing task for phpunit. Phing generates compatible xml.