我有一些我想经常运行的单元测试,还有一些(比如硒功能测试)很慢,需要更多设置。此外,当ci服务器运行测试时,需要报告三叶草,我并不总是想要它们。
有没有办法将开关添加到xml配置?或者它最好保留多个不同的配置并每次告诉它哪个?
答案 0 :(得分:1)
保持多重配置是一种很好的常用方法。
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常量,以“标记”你所在的位置,并决定在测试中运行什么。
// 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
}