我有一个这样的测试用例嵌套结构:
ControllersTestCase -> ControllerTest
ControllersTestCase -> WidgetTestCase -> WidgetTest
OtherTestCase -> OtherTest
当我运行测试时,我想排除所有扩展 ControllersTestCase
的测试。
我试过像这样向 ControllersTestCase
添加 @group 注释
/**
* @group controllers
*/
class ControllerTestCase extends \Zend_Test_PHPUnit_ControllerTestCase
对于这种情况,我希望所有 Widget 测试也被排除。
当我运行 phpunit --exclude-group controllers
时,测试仍在执行。
我在 ControllerTestCase
下有很多测试,所以这是访问所有测试并向每个测试添加 @group
的最后一个选项。
那么我该怎么做才能排除所有继承自 ControllersTestCase
的测试?
最佳答案
关于类的 PHPDoc 继承的一点
Perhaps the simplest of all elements, because a DocBlock for a class makes full use of the object-oriented principles that PHP offers and inherits the following information from the superclass (unless overridden):
Summary
Description
The following tags:
author copyright package subpackage version
用 PHPUnit 排除测试
三种方法:
- 使用
@group
PHPDoc 标签(但这需要大量工作) - 使用
<exclude>
phpunit.xml
中的标签并指定要排除的路径 - 使用
martTestAsSkipped
内拨setUp
要开始跳过测试的类的方法。所有的子类都会继承它。 (这可能是你的赌注,虽然使用xml
配置文件更干净和敏捷。但后者可能会很痛苦,因为要指定这些路径)
关于Phpunit 基于 TestCase 从执行中排除测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40040243/