2017-05-24 30 views
0

这个问题对我来说就是找到一种方法来改进我的测试。当我测试的代码,我通常使用此代码:PHPUnit从测试中得到很好的反馈

$this->assertContains('textExample', $client->getResponse()->getContent()); 

当测试得到OK一切都是正确的,但是当测试从PHPUnit的失败反馈是如此沉重,因为PHP单位回声终端的所有页面进入搜索文本示例。 我会筛选$ client-> getResponse() - > getContent()),并在我搜索它的网站的精确部分搜索textExample(div,h2 ...),并且没有那个重要的反馈形式phpunit。

我希望我很清楚,如果不是,我会尝试重新解释。

回答

0

为什么不使用tearDwon()onNotSuccessfulTest()方法。这样你可以处理错误和过滤,如果你需要。

举例来说,你可以尝试这样开始:

public function onNotSuccessfulTest($e) { 
    // inspect $e to get the information you need, for ie: 
    print_r(get_class_methods($e)); die(); 
    parent::onNotSuccessfulTest($e); 
} 

检查here以获取更多信息。

+0

以及哪种方式来使用它?我认为像$ client-> getResponse() - > getContent() - > filter('div .inThisDiv') – NicolaPez

+0

@NicolaPez我用get_class_methods更新了答案,因此您可以检查$ e上的可用方法 – lloiacono

+0

@NicolaPez我没有看到更新,这对你仍然有用吗?我的回答有帮助吗? – lloiacono