We are looking at switching from phpundercontrol to Hudson (it looks to have some really cool features!) but I can\'t figure out how to get phpunit logs to show up.
I typically work with CruiseControl for PHP testing (using CC's Phing support, not phpundercontrol). I have only worked with Hudson a little, but have gotten Hudson to successfully record phpunit tests using phing's phpunit support.
The following instructions assume that you will be using Phing (not Ant) to manage your PHP project builds and that you have the necessary prereqs installed. It also assumes you have PHPUnit 3 installed (though PHPUnit 2.x should work too).
Step 1: Setup Project for Phing/PHPUnit
First you need to make sure that your project is testable using Phing. Here's a sample Phing build.xml that runs unit tests and creates a JUnit-compatible XML output.
<?xml version="1.0" ?>
<project name="Test Project" default="test">
<property name="tests.dir" value="." />
<property name="reports.dir" value="${tests.dir}/reports" />
<target name="test" description="Run PHPUnit tests">
<phpunit haltonerror="true" haltonfailure="true" printsummary="true">
<batchtest>
<fileset dir="${tests.dir}">
<include name="**/*Test.php" />
</fileset>
</batchtest>
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" todir="${reports.dir}" outfile="test-results.xml" />
</phpunit>
</target>
</project>
Step 2: Setup Hudson
Step 3: Build!
That should do it. Try building your project now. Hopefully it will collect the results.
Also see this Phing presentation, or this Phing presentation for more on Phing and (to a lesser extent) PHPUnit integration.
Good luck!
The format of the XML emitted by PHPUnit is not (currently) compatible with Hudson because it is not quite the same as the XML generated by other similar tools. That's why you get the "None of the test reports contained any result" message.
Short of fixing PHPUnit to generate "better" XML or improving Hudson to be more flexible in what it accepts, the only solution is to fix the XML by eliminating the nesting of <testuite> elements. I've used sed to alter the PHPUnit XML so that it is acceptable to Hudson:
# 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
The answer above is valid but more simply, without changing your build process :
The XSLT transformation from the previous post doesn't works for me. After applying this transformation DOM structure of the report is not changed. I've modified it to fix the problem. My variant is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name="testsuites">
<xsl:for-each select="//testsuite[@file]/testsuite">
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
it works for me.
If you would like a complete tutorial on integrating PHP with Hudson you can check out this link:
Continuous Integration for PHP with Hudson
you can also use this xslt file to convert phpunit xml to hudson/junit xml:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name="testsuites">
<xsl:for-each select="//testsuite[@file]">
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>