How to run single test method with phpunit?
I am struggling to run a single test method named testSaveAndDrop
in the file escalation/EscalationGroupTest.php
with phpunit
. I tried the following combinations:
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
In each case all test methode in the file escalation/EscalationGroupTest.php
are executed. How to select just ONE method instead?
The name of the class is EscalationGroupTest
and the version of phpunit
is 3.2.8.
以下命令在单个方法上运行测试:
phpunit --filter testSaveAndDrop EscalationGroupTest escalation/EscalationGroupTest.php
phpunit --filter methodName ClassName path/to/file.php
I prefer marking the test in annotation as
/**
* @group failing
* Tests the api edit form
*/
public function testEditAction()
Then running it with
phpunit --group failing
No need to specify the full path in the command line, but you have to remember removing this before commit, not to clutter the code.
You may also specify several groups for a single test
/**
* @group failing
* @group bug2204
*/
public function testSomethingElse()
{
}
Here's the more generic answer:
If you are sure the method name is unique you can only filter by method name (this works for me)
phpunit --filter {TestMethodName}
However it is safer to specify the file path/reference as well
phpunit --filter {TestMethodName} {FilePath}
Example:
phpunit --filter testSaveAndDrop reference/to/escalation/EscalationGroupTest.php
Quick note: I've noticed that if I have a function named testSave
and another function named testSaveAndDrop
using command phpunit --filter testSave
will also run testSaveAndDrop
and any other function that starts with testSave*
, it's weird!!
上一篇: 如何在使用数据提供者时保持较小的测试?
下一篇: 如何使用phpunit运行单一测试方法?