有没有办法从tearDown()判断我的PHPUnit测试案例中是否有失败? [英] Is there a way to tell whether there are failures in my PHPUnit test case from tearDown()?

查看:102
本文介绍了有没有办法从tearDown()判断我的PHPUnit测试案例中是否有失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我而言,最好的检查PHPUnit是否成功执行测试的方法是什么?我正在尝试为Selenium窗口拍摄屏幕截图,但是仅当测试失败时才可以.我曾尝试在onNotSuccessfulTest中截取屏幕截图,但是如果我总是在tearDown()中关闭窗口(我应该这样做),则在onNotSuccessfulTest函数中没有会话可以截取屏幕截图.

What's the best way for me to check in PHPUnit whether my test execution succeeded or failed? I am trying to take a screenshot for my Selenium window, but only when my test has failed. I've tried taking a screenshot in onNotSuccessfulTest, but if I am always closing my window in tearDown() (which I should be doing), then there is no session to take the screenshot with in my onNotSuccessfulTest function.

我正在考虑的解决方案包括检查在拆解中测试是成功还是失败,确定是否要截屏.

The solution I'm thinking of involves checking for whether the test succeeded or failed in the tearDown, determining whether or not to take a screenshot.

我正在使用PHPUnit 3.6和Facebook的php-webdriver,据我所知,我没有变量captureScreenshotOnFailure.

I am using PHPUnit 3.6 and Facebook's php-webdriver, so as far as I know, I don't have the variable captureScreenshotOnFailure.

有想法吗?

推荐答案

您可以检查getStatus()的返回值,并在所需条件下截屏.

You can check the return value from getStatus() and take a screenshot under your desired conditions.

protected function tearDown() {
    $status = $this->getStatus();
    if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR 
            || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
        // take a screenshot...
    }
}

有关根据测试方法引发的异常设置状态的位置,请参见runBare().您可能还想为跳过的测试拍摄屏幕截图.

See runBare() for where the status is set based on the exception thrown from the test method. You might want to take a screenshot for skipped tests too.

这篇关于有没有办法从tearDown()判断我的PHPUnit测试案例中是否有失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆