2014-01-09 53 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.