jdp*_*jdp 14 php phpunit unit-testing
我的PHPUnit配置文件有两个测试套件,unit和system.当我运行测试运行器时vendor/bin/phpunit,它会在两个套件中运行所有测试.我可以使用testsuite标志来定位单个套件:vendor/bin/phpunit --testsuite unit但是我需要将测试运行器配置为unit默认情况下仅运行套件,并且integration仅在使用testsuite标志进行专门调用时运行.
我的配置:
<?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>
Run Code Online (Sandbox Code Playgroud)
Gar*_*ryJ 20
从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>
Run Code Online (Sandbox Code Playgroud)
你现在可以运行phpunit而不是phpunit --testsuite unit.
测试套件的名称可能区分大小写,因此请注意.
似乎没有一种方法可以从 phpunit.xml 文件中列出多个测试套件,但只能运行一个。然而,如果您确实对更全面的集成和测试环境有一定的控制权,可以更准确地进行配置,那么您可以拥有多个 phpunit 配置文件,并设置一个(或多个)涉及更多的环境来设置命令行参数--configuration <file>选项与配置将执行更多操作。这至少确保最简单的配置将以最简单的方式运行。
如果您专门运行这两个文件,则可以将它们命名为任何您喜欢的名称,但可能值得考虑将快速运行的文件称为 default phpunit.xml,并将专门命名和扩展的文件命名为phpunit.xml.dist. 如果原始plain不存在,.dist文件将默认自动运行.xml。另一种选择是将phpunit.xml.dist文件放在代码存储库中,然后将其复制到一个phpunit.xml文件,其中包含较少的测试套件,该文件本身并未签入版本控制,并且仅保存在本地(它也可能在.gitignore 文件或类似文件)。