How to skip tests in PHPunit?

PhpPhpunit

Php Problem Overview


I am using phpunit in connection with jenkins, and I want to skip certain tests by setting the configuration in the XML file phpunit.xml

I know that I can use on the command line:

phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest

how do I translate that to the XML file since the <filters> tag is only for code-coverage?

I would like to run all tests apart from testStuffThatAlwaysBreaks

Php Solutions


Solution 1 - Php

The fastest and easiest way to skip tests that are either broken or you need to continue working on later is to just add the following to the top of your individual unit test:

$this->markTestSkipped('must be revisited.');

Solution 2 - Php

If you can deal with ignoring the whole file then

<?xml version="1.0" encoding="UTF-8"?>

<phpunit>

    <testsuites>
        <testsuite name="foo">
            <directory>./tests/</directory>
            <exclude>./tests/path/to/excluded/test.php</exclude>
                ^-------------
        </testsuite>
    </testsuites>

</phpunit>

Solution 3 - Php

Sometimes it's useful to skip all tests from particular file based on custom condition(s) defined as php code. You can easily do that using setUp function in which makeTestSkipped works as well.

protected function setUp()
{
    if (your_custom_condition) {
        $this->markTestSkipped('all tests in this file are invactive for this server configuration!');
    }
}

your_custom_condition can be passed via some static class method/property, a constant defined in phpunit bootstrap file or even a global variable.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfilypeView Question on Stackoverflow
Solution 1 - PhpjsteinmannView Answer on Stackoverflow
Solution 2 - PhpzerkmsView Answer on Stackoverflow
Solution 3 - PhpKonrad GałęzowskiView Answer on Stackoverflow