我的一些测试用例使用自定义测试库.这些测试用例也很慢.所以我想只在构建服务器中运行它们而不是在本地运行它们.我想在本地运行其他测试.
以下是目录结构.里面的那些slow目录是缓慢的测试用例应该被排除在外.
/tests/unit-tests/test-1.php
/tests/unit-tests/test-2.php
/tests/unit-tests/slow/test-1.php
/tests/unit-tests/slow/test-2.php
/tests/unit-tests/foo/test-1.php
/tests/unit-tests/bar/test-2.php
Run Code Online (Sandbox Code Playgroud)
我尝试使用@group注释创建组.这有效,但问题是这些测试文件正在加载(虽然测试没有执行).由于它们需要未在本地安装的测试库,因此会出错.
创建phpunit.xml配置的最佳方法是什么,默认情况下排除(甚至不加载)这些慢速测试,如果需要可以执行?
有两种选择:
1)在你的phpunit.xmlcreate 2测试服中 - 一个用于CI服务器,一个用于本地开发
<testsuites>
<testsuite name="all_tests">
<directory>tests/unit-tests/*</directory>
</testsuite>
<testsuite name="only_fast_tests">
<directory>tests/unit-tests/*</directory>
<!-- Exclude slow tests -->
<exclude>tests/unit-tests/slow</exclude>
</testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)
所以在CI服务器上你可以运行
phpunit --testsuite all_tests
Run Code Online (Sandbox Code Playgroud)
在当地
phpunit --testsuite only_fast_tests
Run Code Online (Sandbox Code Playgroud)
显然,您可以根据需要命名测试套件.
2)我认为最好的方法是:
phpunit.xml.dist和配置phpunit的默认执行(对于CI服务器和所有刚刚克隆存储库的人)phpunit.xml通过配置的PHPUnit的本地执行(通过添加<exclude>tests/unit-tests/slow</exclude>到默认测试套件)phpunit.xml从版本控制中排除.来自文档:
如果当前工作目录中存在phpunit.xml或phpunit.xml.dist(按此顺序)并且未使用--configuration,则将自动从该文件中读取配置.
一些链接:
| 归档时间: |
|
| 查看次数: |
1325 次 |
| 最近记录: |