hello world!
Published: February 18, 2011

Ant Groovy target to create Hudson compatible PHPUnit XML report

Hudson JUnit PHPUnit Ant Groovy

While setting up a Hudson CI and deployment solution for some PHP projects I ran into a problem getting the PHPUnit reports to integrate properly into the builds.

I kept getting the error:

Recording test results
None of the test reports contained any result

It seems that the report XML that PHPunit creates with the option for "--log-junit" is formatted differently than Hudson expects; adding extra "testcase" nodes.

After some research I found a thread discussing the problems with some users providing an XSLT file to convert the PHPUnit format to a format Hudson will understand.

With this I information I added an Ant target in my CI build.xml workflow to transform the XML using a Groovy Ant task.

I call this task after my PHPUnit task has created my "--log-junit" report named "junit-phpunit.xml" and save the transformed XML to my final "junit.xml" that I have configured the Hudson's post-build "Publish JUnit test result report" action to use.

import java.xml.transform.TransformerFactory
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource

def xslt = '''



def factory = TransformerFactory.newInstance()
def transformer = factory.newTransformer(
    new StreamSource(new StringReader(xslt))
    new StreamSource(
        new File("${properties.basedir}/build/logs/junit-phpunit.xml")
    ), new StreamResult(
        new File("${properties.basedir}/build/logs/junit.xml")

Leave a Reply