LoginSignup
2
2

More than 5 years have passed since last update.

WP_UnitTestCaseのちょっと変わったテストを見てみる(knownWPBug編)

Last updated at Posted at 2017-01-10

http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/testcase.php を見ていると、「そんなテスト / ヘルパー関数もあるのか」というものを時より見かけるので、ピックアップしてみます。

knownWPBug( $ticket_id )

$ticket_idに対応するチケットがオープンになっている場合、該当のテストをスキップします。

テストコード

class SampleTest extends WP_UnitTestCase {

    /**
     * A single example test.
     */
    function test_some_core_bug_opend() {
        // クローズされていないチケットの場合
        // https://core.trac.wordpress.org/ticket/38653
        $this->knownWPBug( 38653 );
    }
    function test_some_core_bug_closed() {
        // すでにクローズされているチケットの場合
        // https://core.trac.wordpress.org/ticket/100
        $this->knownWPBug( 100 );
    }
}

テスト実行結果

$ phpunit
/tmp/wordpress-tests-libInstalling...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 5.7.3 by Sebastian Bergmann and contributors.

S.                                                                  2 / 2 (100%)

Time: 2.16 seconds, Memory: 26.00MB

OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 0, Skipped: 1.

1つ目のテストtest_some_core_bug_opend()がスキップされました。

クローズ済のテストはスキップされずに実行されています。

使い所を想像してみた

コアのバグを拾ってしまった時に、そのコアのバグが影響するテストをスキップさせることで、テストをFailさせないようにするという使い方なのかなと思います。

でなければチケット番号指定で実行させるというやり方にはならないと思いますし。

該当チケットが解決されればテストはそのまま実行されますので、バグが修正されたらコードを消さないといけないというわけでもなさそうです。

余談

サンプルで使った以下のチケットですが、Good First Bugsとよばれる「はじめてWordPressコアにバッチを送ってみよう」と思った人のための簡単なバグです。
https://core.trac.wordpress.org/ticket/38653

コア開発などに興味がある方は、ぜひ挑戦してみてください。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2