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.
How to Run Tests in PHPUnit. You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status.
Sometimes when you're trying to nail down a failing test you need a quick way to run just the thing thats broken, instead of your whole suite or a whole test case. Fortunately it's pretty simple with the --filter flag provided by PHPUnit.
PHPUnit provides methods that are used to automatically create objects that will replace the original object in our test. createMock($type) and getMockBuilder($type) methods are used to create mock object. The createMock method immediately returns a mock object of the specified type.
PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit. PHPUnit was created by Sebastian Bergmann and its development is hosted on GitHub.
The following command runs the test on a single method:
phpunit --filter testSaveAndDrop EscalationGroupTest escalation/EscalationGroupTest.php phpunit --filter methodName ClassName path/to/file.php
For newer versions of phpunit, it is just:
phpunit --filter methodName 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() { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With