当 Spock 测试失败时执行一些操作 [英] Execute some action when Spock test fails

查看:39
本文介绍了当 Spock 测试失败时执行一些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Spock 测试失败时执行一些操作.具体来说,截图.是否可以?怎么做?

I'd like to execute some action when Spock test fails. Specifically, take a screenshot. Is it possible? How to do it?

推荐答案

创建监听器类

class ExampleListener extends AbstractRunListener {

  def void error(ErrorInfo error) {
    println "Actual on error logic"
  }
}

然后使用为每个规范执行的 IGlobalExtension 的实现将其添加到每个规范

then add it to each specification using implementation of IGlobalExtension that is executed for each Spec

class GlobalSpecExtension implements IGlobalExtension {

  @Override
  void visitSpec(SpecInfo specInfo) {
    specInfo.addListener(new ExampleListener())
  }
}

最后在您的 META-INF/services 目录 中创建名为 org.spockframework.runtime.extension.IGlobalExtension 的文件(通常它会在 src/test/resources(如果您使用的是 Maven)和您的 IGlobalExtension 实现的全名,例如

and finally create file named org.spockframework.runtime.extension.IGlobalExtension in your META-INF/services directory (typically it will be under src/test/resources if you are using Maven) with the full name of your IGlobalExtension implementation e.g.

com.example.tests.GlobalSpecExtension

这篇关于当 Spock 测试失败时执行一些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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