我通常使用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