Phpunit 基于 TestCase 从执行中排除测试

标签 php testing phpunit

我有一个这样的测试用例嵌套结构:

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/

相关文章:

ruby-on-rails - 未初始化常量 MiniTest::测试错误

jquery - Symfony2 功能测试 - 通过 jQuery 交互单击元素

php - Yahoo 发送 PM 算法

angularjs - Angular 应用程序的最大圈复杂度

php - PHP中的数组求和

c# - 使用 Moq 测试抽象类

php - Yii 单元测试 CDbException

php - PHPUnit 测试期间 GitLab-CI 出现 file_get_contents 问题

PHP 正则表达式 - 从字符串的开头和结尾匹配

php - 用 BR 标签替换换行符,但只在 PRE 标签内