我正在努力使用phpunit在文件escalation/EscalationGroupTest.php中运行一个名为testSaveAndDrop的测试方法。我尝试了以下组合:

phpunit EscalationGroupTest escalation/EscalationGroupTest.php --filter=escalation/EscalationGroupTest.php::testSaveAndDrop
phpunit EscalationGroupTest escalation/EscalationGroupTest.php --filter=EscalationGroupTest.php::testSaveAndDrop
phpunit EscalationGroupTest escalation/EscalationGroupTest.php --filter=EscalationGroupTest::testSaveAndDrop
phpunit EscalationGroupTest escalation/EscalationGroupTest.php --filter=testSaveAndDrop

在每种情况下,都会执行文件escalation/EscalationGroupTest.php中的所有测试方法。如何选择只有一个方法,而不是?

类的名称是EscalationGroupTest, phpunit的版本是3.2.8。


当前回答

为在laravel中运行phpunit测试提供了多种方法。

vendor/bin/phpunit --filter methodName className pathTofile.php

vendor/bin/phpunit --filter 'namespace\\directoryName\\className::methodName'

对于测试单类:

vendor/bin/phpunit --filter  tests/Feature/UserTest.php
vendor/bin/phpunit --filter 'Tests\\Feature\\UserTest'
vendor/bin/phpunit --filter 'UserTest' 

测试单一方法:

 vendor/bin/phpunit --filter testExample 
 vendor/bin/phpunit --filter 'Tests\\Feature\\UserTest::testExample'
 vendor/bin/phpunit --filter testExample UserTest tests/Feature/UserTest.php

对于从命名空间中的所有类运行测试:

vendor/bin/phpunit --filter 'Tests\\Feature'

有关更多方式运行测试,请参阅更多

其他回答

就像这样

phpunit --filter 'EscalationGroupTest::testSaveAndDrop' EscalationGroupTest escalation/EscalationGroupTest.php 

没有=和有'

https://phpunit.de/manual/3.7/en/textui.html

下面的命令在单个方法上运行测试:

phpunit --filter testSaveAndDrop EscalationGroupTest escalation/EscalationGroupTest.php

phpunit --filter methodName ClassName path/to/file.php

对于phpunit的新版本,它只是:

phpunit --filter methodName path/to/file.php

为在laravel中运行phpunit测试提供了多种方法。

vendor/bin/phpunit --filter methodName className pathTofile.php

vendor/bin/phpunit --filter 'namespace\\directoryName\\className::methodName'

对于测试单类:

vendor/bin/phpunit --filter  tests/Feature/UserTest.php
vendor/bin/phpunit --filter 'Tests\\Feature\\UserTest'
vendor/bin/phpunit --filter 'UserTest' 

测试单一方法:

 vendor/bin/phpunit --filter testExample 
 vendor/bin/phpunit --filter 'Tests\\Feature\\UserTest::testExample'
 vendor/bin/phpunit --filter testExample UserTest tests/Feature/UserTest.php

对于从命名空间中的所有类运行测试:

vendor/bin/phpunit --filter 'Tests\\Feature'

有关更多方式运行测试,请参阅更多

下面的命令将精确地执行testSaveAndDrop test。

phpunit --filter '/::testSaveAndDrop$/' escalation/EscalationGroupTest.php

您必须使用——filter来运行单个测试方法 php phpunit——filter "/::testMethod(.*)?ClassTest.php

上面的过滤器将单独运行testMethod。