简体   繁体   English

没有在PHPUnit中运行一些测试?

[英]Not run some tests in PHPUnit?

I don't want to run all the tests sometimes to save time. 我有时不想运行所有测试以节省时间。 I know I can comment the tests. 我知道我可以评论测试。 But this method isn't elegant. 但这种方法并不优雅。 I'm wondering whether there is some simple way to do that. 我想知道是否有一些简单的方法可以做到这一点。

All advice is appreciated. 所有建议表示赞赏。

Thanks for your time and best regards, Box He 谢谢你的时间和最好的问候,Box He

@group @组

A test can be tagged as belonging to one or more groups using the @group annotation like this 可以使用@group注释将测试标记为属于一个或多个组

class MyTest extends PHPUnit_Framework_TestCase
{
    /**
     * @group specification
     */
    public function testSomething()
    {
    }

    /**
     * @group regresssion
     * @group bug2204
     */
    public function testSomethingElse()
    {
    }
}

Tests can be selected for execution based on groups using the --group and --exclude-group switches of the command-line test runner or using the respective directives of the XML configuration file. 可以使用命令行测试运行器的--group和--exclude-group开关或使用XML配置文件的相应指令,基于组选择测试以执行。

phpunit command line test runner has --filter argument which is a regular expression to match the executed test case names. phpunit 命令行测试运行器--filter参数,它是一个匹配执行的测试用例名称的正则表达式。

Suppose, you need to exclude all the test cases, names of which contain "Foo". 假设您需要排除所有包含“Foo”的测试用例。 Then, use: 然后,使用:

--filter /^(?:(?!Foo).)*$/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM