如何从Codeception单元测试获得调试输出?

时间:2014-01-09 12:05:28

标签: phpunit 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中获得某种有用的调试输出(就像你获得验收测试一样)...... / p>

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

单元测试可以吗?

1 个答案:

答案 0 :(得分: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.