web-dev-qa-db-ja.com

PHPunitでテストをスキップする方法は?

Jenkinsに関連してphpunitを使用しています。XMLファイルphpunit.xmlで構成を設定することにより、特定のテストをスキップしたいです。

私はコマンドラインで使用できることを知っています:

phpunit --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest

<filters>タグはコードカバレッジ専用であるため、XMLファイルに変換するにはどうすればよいですか?

testStuffThatAlwaysBreaks以外のすべてのテストを実行したい

68
Filype

壊れているか、後で作業を続ける必要があるテストをスキップするための最速かつ最も簡単な方法は、個々の単体テストの先頭に次を追加することです。

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

ファイル全体を無視して対処できる場合

<?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>
28
zerkms

PHPコードとして定義されたカスタム条件に基づいて、特定のファイルからすべてのテストをスキップすると便利な場合があります。 makeTestSkippedが同様に機能するsetUp関数を使用して簡単に実行できます。

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

your_custom_conditionは、静的なクラスメソッド/プロパティ、phpunitで定義された定数bootstrap fileまたはグローバル変数を介して渡すことができます。

15