问题描述
我的PHPUnit配置文件有两个测试套件,unit
和system
.当我运行测试运行程序vendor/bin/phpunit
时,它将运行两个套件中的所有测试.我可以使用testsuite
标志针对单个套件:vendor/bin/phpunit --testsuite unit
,但是我需要将测试运行程序配置为默认情况下仅运行unit
套件,并且仅在使用testsuite标志专门调用时才运行integration
My PHPUnit configuration file has two test suites, unit
and system
. When I run the test runner vendor/bin/phpunit
, it runs all tests in both suites. I can target a single suite with the testsuite
flag: vendor/bin/phpunit --testsuite unit
, but I need to configure the test runner to run only the unit
suite by default, and to run integration
only when specifically called with the testsuite flag.
我的配置:
<?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>
推荐答案
似乎没有一种方法可以从phpunit.xml文件中列出多个测试套件,但只能运行一个.但是,如果您确实对更完整的集成和测试环境有一定的控制权,可以在其中进行更精确的配置,则可以拥有多个phpunit配置文件,并在涉及更多环境的情况下设置一个(或多个)设置命令行参数--configuration <file>
选项,该配置将执行更多操作.至少可以确保最简单的配置将以最简单的方式运行.
There doesn't appear to be a way to list multiple testsuites from a phpunit.xml file, but then only run one. However, if you do have some control over a fuller integration and testing environment where you can configure things more exactly, you can have more than one phpunit configuration files, and set one (or more) with more involved environments to set the command-line parameter --configuration <file>
option with a configuration that will do more. This at least makes sure that the simplest config will run in the easiest fashion.
如果您专门运行它们,可以随意命名这两个文件,但值得考虑的是将快速运行的文件称为默认文件phpunit.xml
,并将专门命名和扩展的文件m命名为. 如果原始普通.xml
不存在,默认情况下将自动运行.dist文件.另一个选择是将phpunit.xml.dist
文件保存在代码存储库中,然后将其复制到phpunit.xml
文件中,使用较少的测试套件,其本身不会检入版本控制中,而仅保存在本地(可能还会在.gitignore文件或类似文件中被标记为已忽略.
The two files can be called whatever you like if you run them specifically, but it may be worth thinking about having the quick-to-run file called the default phpunit.xml
, and the specifically named and extended filem as phpunit.xml.dist
. The .dist file will be automatically run by default if the original plain .xml
does not exist. Another option is to have the phpunit.xml.dist
file in a code repository, but then copy it to a phpunit.xml
file, with less testsuite's, which is not in itself checked into version control, and is only kept locally (it would probably also be marked as ignored in a .gitignore file, or similar).
这篇关于默认情况下在PHPUnit中运行一个测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!