在 PHPUnit 中默认运行单个测试套件

Running a single testsuite by default in PHPUnit(在 PHPUnit 中默认运行单个测试套件)
本文介绍了在 PHPUnit 中默认运行单个测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

My configuration:

<?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>

解决方案

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.

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 中默认运行单个测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)