我通常使用CruiseControl进行PHP测试(使用CC的Phing支持,而不是phpundercontrol)。我只与Hudson合作一点,但是已经让Hudson成功使用phing的phpunit支持来记录phpunit测试。
以下说明假定您将使用Phing(而非Ant)来管理您的PHP项目构建,并且您已安装必要的prereq。它还假定你已经安装了PHPUnit 3(尽管PHPUnit 2.x也应该可以工作)。
步骤1:Phing安装项目/ PHPUnit的
首先,你需要确保你的项目是可测试使用Phing。下面是一个示例Phing build.xml,它运行单元测试并创建JUnit兼容的XML输出。
<?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>
步骤2:设置哈德森
- 安装Phing插件哈德森。请注意,您可能需要将作为独立软件包安装(我将它放在/opt/phing-2.3.3中)并在Hudson配置中将PHING_HOME配置为指向该目录。你也应该能够使用PEAR安装的Phing;不过,我还没有测试过。
- 配置Hudson使用Phing构建您的项目。
- 配置Hudson从项目中收集JUnit测试。我们的结果文件的名称将是test-results.xml。在上面的例子中,您将其配置为从reports/*。xml收集文件。
第3步:建立!
应该这样做。现在尝试构建您的项目。希望它能收集结果。
另请参阅此Phing presentation或此Phing presentation了解更多有关Phing和(较小程度上)PHPUnit集成的信息。
祝你好运!上述
仅供参考... - 不赞成使用--log-xml标志。改用--log-junit。 – fitzgeraldsteele 2010-09-10 15:19:58