簡體   English   中英

有沒有一種簡單的方法來管理多個phpunit配置?

[英]Is there an easy way to manage multiple phpunit configurations?

我有一些我想經常運行的單元測試,而另一些(例如硒功能測試)則運行緩慢且需要更多設置。 另外,當ci服務器運行測試時,需要三葉草報告,我並不總是想要它們。

有沒有辦法將開關添加到xml配置? 還是最好保留多個不同的配置並每次告訴它?

保留多個配置是一種很好的通用方法。

phpunit.xml.dist
phpunit.xml.travis
phpunit.xml.jenkins
phpunit.xml.ci

這樣就可以僅在一個文件中激活記錄器三葉草,就像在CI“ phpunit.xml.jenkins”上一樣。 但是,當調用phpunit時,可以將其附加到CLI“-coverage-clover”上。

另一種選擇是將測試分為“慢速”和“快速”。 為此,您需要@group批注。

// phpunit.xml.ci
<groups>
  <include>
    <group>fast</group>
  </include>
  <exclude>
    <group>slow</group>
  </exclude>
</groups>

在CLI中,也可以使用“ --group”,“-exclude-group”等選項。

http://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.group

也可以將phpunit配置文件中的PHP常量設置為“標記”您所在的位置,並決定在Tests中運行什么。

// in phpunit.xml.*
<php>
   <const name="PHPUNIT_RUNS_ON_CI_SERVER" value="true"/>
</php>

// somewhere in a PHP test file
if (defined('PHPUNIT_RUNS_ON_CI_SERVER') === 1)
{ 
    // run CI stuff
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM