Run a single test with phpUnit

3.4k views Asked by At

I'm currently introducing tests in my Symfony app. Some of them are failing and it takes ages to run them all.

Is it possible to run a single test with the simpl-phpunit command ?

I already tested :

with the namespace of my test but ended up with

./vendor/bin/simple-phpunit App\tests\Controller\DefaultControllerTest

Cannot open file "ApptestsControllerDefaultControllerTest.php".

and with the relative path to my Test, ut it leads to:

./vendor/bin/simple-phpunit tests/Controller/DefaultControllerTest

Cannot open file "tests/Controller/DefaultControllerTest.php".

1

There are 1 answers

1
T. Altena On BEST ANSWER

Can you try running the full phpunit executable?

./vendor/bin/phpunit tests/Controller/DefaultControllerTest

The second version of the command should work. You can go even more fine-grained than testfiles by putting an @group in the PHPdoc part to run individual functions like so:

/**
 * A basic test example.
 * @group test
 * @return void
 */

public function testHomePage()
{
    // basic get test
    $this->get('')->assertStatus(200)
        ->assertSee('Home');
}

run it with

./vendor/bin/phpunit --group=test