Running a Single PHPUnit Test

Debugging Testing

Committed to the LaraBrain by: wjgilmore (@wjgilmore) at October 28, 2015 11:06 am

As your PHPUnit test suite grows you'll often only want to execute one or a few tests. Here's how.

As your test suite grows, so will the time required to execute all of the tests. If you're working on implementing a few or just a single test, this turnaround time can quickly grow tedious. Fortunately, PHPUnit supports test annotation, allowing you to identify one or more tests by a keyword which can then be used as a filter when running the suite. In the following example I've annotated a test with the group keyword failing:

 * @group failing
public function testUnauthenticatedUserCantSeeSubmitTipForm()

With the annotation in place, I can instruct PHPUnit to execute just this test like so:

$ phpunit --group failing