Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ignore a test method in phpunit without modifying its content?

What is the attribute that should be placed next to the PHP test method in order to ignore the test using PHPUnit ?

I know that for NUnit the attribute is :

[Test]
[Ignore]
public void IgnoredTest()
like image 610
Gabriel Diaconescu Avatar asked Sep 01 '25 18:09

Gabriel Diaconescu


2 Answers

You can tag the test with a group annotation and exclude those tests from a run.

/**
 * @group ignore
 */
public void ignoredTest() {
    ...
}

Then you can run the all the tests but ignored tests like this:

phpunit --exclude-group ignore
like image 164
Brady Olsen Avatar answered Sep 04 '25 06:09

Brady Olsen


The easiest way would be to just change the name of the test method and avoid names starting with "test". That way, unless you tell PHPUnit to execute it using @test, it won't execute that test.

Also, you could tell PHPUnit to skip a specific test:

<?php
class ClassTest extends PHPUnit_Framework_TestCase
{     
    public function testThatWontBeExecuted()
    {
        $this->markTestSkipped( 'PHPUnit will skip this test method' );
    }
    public function testThatWillBeExecuted()
    {
        // Test something
    }
}
like image 41
Jose Armesto Avatar answered Sep 04 '25 07:09

Jose Armesto