2

私はここで太っているかもしれませんが、テストが失敗した理由について少し情報を取得する方法がわかりません.

たとえば、テストのない新しいメソッドがないことを確認するために、このテストがあります...

//TEST ALL METHODS TESTED
public function testAllMethodsTested()
{
    $temp = $this->class_namespace.substr(__CLASS__, 0, -5);
    $class_methods = get_class_methods($temp);
    $test_methods = get_class_methods(__CLASS__);

    foreach($class_methods as $class_method) 
    {
        $this->assertEquals(true, in_array('test_'.$class_method, $test_methods));
    }
}

これが失敗すると、次のような結果になります...

1) c_functions_core_ext_Test::testAllMethodsTested
Failed asserting that false matches expected true.

どこに行っていくつかのコードを修正するかを簡単に確認できるようにするために、次の行に沿って、コンソールと report.html (受け入れテストで得られるようなもの) である種の役立つデバッグ出力を取得したいと思います...

1) some_class_Test::testAllMethodsTested
Checking test exists for some_class::someMethod
Failed asserting that false matches expected true.

これは単体テストで可能ですか?

4

1 に答える 1

3

はい、私は太っています。アサート関数を使用すると、独自のメッセージを指定できるようです...

//TEST ALL METHODS TESTED
public function testAllMethodsTested()
{
    $target_class = $this->class_namespace.substr(__CLASS__, 0, -5);
    $class_methods = get_class_methods($target_class);
    $test_methods = get_class_methods(__CLASS__);

    $result = in_array('test_'.$class_method, $test_methods);

    //FAIL WITH A USEFUL ERROR
    $this->assertTrue($result, 'There is no test for '.$target_class.'::'.$class_method);
}

これが失敗すると、次のようなものが得られます...

1) c_functions_core_ext_Test::testAllMethodsTested
There is no test for Namespace\target_class::someMethodName
Failed asserting that false matches expected true.
于 2014-01-13T11:13:19.540 に答える