2016-06-14 111 views
8

我的PHPUnit配置文件有两个测试套件,分别为unitsystem。当我运行测试跑步者vendor/bin/phpunit时,它将在两个套件中运行所有测试。我可以使用testsuite标志:vendor/bin/phpunit --testsuite unit来标记一个套件,但我需要配置测试运行器默认情况下仅运行unit套件,并且只有在使用testsuite标志专门调用时才运行integration默认情况下在PHPUnit中运行单个测试套件

我的配置:

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit colors="true"> 
    <testsuites> 
    <testsuite name="unit"> 
     <directory>tests/Unit</directory> 
    </testsuite> 
    <testsuite name="integration"> 
     <directory>tests/Integration</directory> 
    </testsuite> 
    </testsuites> 
    <filter> 
    <whitelist> 
     <directory suffix=".php">src</directory> 
    </whitelist> 
    </filter> 
    <logging> 
    <log type="coverage-clover" target="build/clover.xml"/> 
    </logging> 
</phpunit> 
+0

建立'phpunit_unit.sh'和'phpunit_integration.sh'文件是不是更好,里面的配置? –

回答

1

似乎没有成为一个方式列出从phpunit.xml文件的多个测试包,但随后只运行一个。但是,如果您确实可以控制更完整的集成和测试环境,并且可以更精确地配置事物,则可以有多个phpunit配置文件,并设置一个(或多个)涉及更多的环境来设置命令行参数--configuration <file>选项与将做更多的配置。这至少可以确保最简单的配置以最简单的方式运行。

如果您专门运行它们,可以调用这两个文件,但可能需要考虑将快速运行的文件称为默认phpunit.xml,以及专门命名和扩展的文件名为phpunit.xml.dist如果原始纯文本.xml不存在,则.dist文件将默认自动运行。另一个选择是将phpunit.xml.dist文件放在代码库中,然后将其复制到phpunit.xml文件中,使用更少的'测试套件,它本身不会检入版本控制,只保存在本地。 (它可能也被标记为在.gitignore文件或类似文件中被忽略)。

+1

PHPUnit(自6.1.0开始)现在支持定义默认测试套件,因此不再需要此解决方法。 – GaryJ

+0

@GaryJ:一个链接(至少),这是从真正的超文本友好。但是,非常感谢评论和版本号:)/E:Ooops,只是看到你在[下面的答案]中有它(https://stackoverflow.com/a/45446071/367456) – hakre

4

由于PHPUnit 6.1.0,现在支持defaultTestSuite属性。

https://github.com/sebastianbergmann/phpunit/pull/2533

这可以用来之中,像这样的其他phpunit属性:

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd" 
     backupGlobals="false" 
     backupStaticAttributes="false" 
     bootstrap="tests/bootstrap.php" 
     colors="true" 
     convertErrorsToExceptions="true" 
     convertNoticesToExceptions="true" 
     convertWarningsToExceptions="true" 
     defaultTestSuite="unit" 
     processIsolation="false" 
     stopOnFailure="false"> 
    <testsuites> 
     <testsuite name="unit"> 
      <directory suffix="Test.php">tests/Unit</directory> 
     </testsuite> 
     <testsuite name="integration"> 
      <directory suffix="Test.php">tests/Integration</directory> 
     </testsuite> 
    </testsuites> 
</phpunit> 

您现在可以运行phpunit而不是phpunit --testusite unit

测试套件的名称可能区分大小写,请注意。

+0

不错的增强知之甚少关于。感谢发布! – hakre