首页 / PHP / php – 记录代码错误
php – 记录代码错误
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 记录代码错误,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2459字,纯文字阅读大概需要4分钟。
内容图文
我对Codeception很新,我遇到了一个我无法弄清楚的问题.我的测试套件中有大约40个测试,如果测试失败,我需要发送一封电子邮件,说明它失败的原因.例如,如果Codeception无法在页面上找到导致测试失败的元素,我需要发送一封只包含错误的电子邮件,如下所示:
Failed to verify emailing wish list behaves as expected in ThisClass::thisTest (/home/qauser/codeception_tests///acceptance-mobile/Wishlist/EmailWishlistCest.php)
Couldn’t see “Success!”,”//*[@id=”wish-list-confirm-popup”]/div/div/div[1]/h4″:
我不想发送完整的堆栈跟踪,只是发送实际的错误.有谁知道这是否可能?
解决方法:
Codeception公开了一个有用的事件集合,这些事件将为这个用例派上用场.有关更多信息,请查看Codeception文档的Customization: Events部分.
我建议拦截该页面上描述的两个事件:
> test.fail事件,用于聚合有关每个失败测试的信息.
> test.fail.print事件,用于在Codeception完成测试套件时处理聚合数据(例如,通过发送摘要电子邮件),并将自己的故障摘要打印到屏幕上.
要实现此目的,您只需构建一个自定义事件处理程序类并将其注册为配置文件中的扩展:
# codeception.yml
extensions:
enabled: [MyCustomEventHandler]
# MyCustomEventHandler.php
<?php
// Note: this was drafted using Codeception 2.0. Some of the namespaces
// maybe different if you're using a more-recent version of Codeception.
class MyCustomEventHandler extends \Codeception\Platform\Extension
{
/**
* @var \Exception[]
*/
protected $testFailures = [];
/**
* Maps Codeception events to method names in this class.
*
* Defining an event/method pair in this array essentially subscribes
* the method as a listener for its corresponding event.
*
* @var array
*/
public static $events = [
\Codeception\Events::TEST_FAIL => 'singleTestJustFailed',
\Codeception\Events::TEST_FAIL_PRINT => 'allTestFailuresAreBeingDisplayed',
];
/**
* This method will automatically be invoked by Codeception when a test fails.
*
* @param \Codeception\Event\FailEvent $event
*/
public function singleTestJustFailed(\Codeception\Event\FailEvent $event)
{
// Here we build a list of all the failures. They'll be consumed further downstream.
$this->testFailures[] = $event->getFail();
}
/**
* This method will automatically be invoked by Codeception when it displays
* a summary of all the test failures at the end of the test suite.
*/
public function allTestFailuresAreBeingDisplayed()
{
// Build the email.
$emailBody = '';
foreach ($this->testFailures as $failure) {
// Methods in scope include: $failure->getMessage(), $failure->getFile(), etc.
$emailBody .= $failure->getMessage() . "\r\n";
}
// Now send the email!
}
}
希望这可以帮助!
内容总结
以上是互联网集市为您收集整理的php – 记录代码错误全部内容,希望文章能够帮你解决php – 记录代码错误所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。