2014-01-09 51 views
1

我可能會在這裏很厚,但我無法弄清楚如何獲得關於爲什麼測試失敗的一些信息。如何從Codeception單元測試獲取調試輸出?

E.g.我有這個測試是有檢查,我們還沒有得到,沒有任何測試的新方法......

//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. 

這是可能的uni噸測試?

回答

2

是的,我很厚。這似乎斷言功能允許指定自己的消息...

//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.