在黄瓜套件之前/之后如何运行代码? [英] How to run code before/after cucumber suite?

查看:99
本文介绍了在黄瓜套件之前/之后如何运行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出在所有黄瓜测试运行之前和之后如何运行一些代码的方法。

I'm trying to figure out how to run some code before and after all my cucumber tests run.

我一直在跟踪一些错误。我们的某些进程在服务器上创建作业的日子,并且没有适当地清理它。很容易错过,因此理想情况下,我不希望工程师必须为每个测试手动添加支票。

I've been tracking down a bug for a few days where some our processes create jobs on a server, and don't properly clean it up. It's easy to miss so ideally I don't want engineers to have to manually add a check to every test.

我希望有一种方法可以在运行任何测试以缓存服务器上存在多少作业之前挂接,然后在末尾挂接以确保值未更改。

I was hoping there'd be a way to put a hook in before any tests ran to cache how many jobs exist on the server, then a hook at the end to ensure that the value hasn't changed.

我知道这一点并不是真正使用黄瓜的最佳方法,因为这更多的是系统测试类型,但是以这种方式进行操作将是使其适合现有基础结构的最佳方法。

I know this isn't really the best way to use cucumber, as that is more of a system test type thing to do, but doing it this way would be the best way to fit it into the existing infrastructure.

推荐答案

如何使用标记的挂钩。

How about using tagged hooks.

@Before("@jobCheck")
public void beforeScenario() {
  // actions
}

@After("@jobCheck")
public void afterScenario() {
  // actions
}

然后对于需要此检查的每个方案,在方案定义之前添加@jobCheck,如下所示。

And then for each scenario that requires this check, add @jobCheck before the Scenario definition as below.

Feature: Some feature description
  @jobCheck
  Scenario: It should process a sentence
    // The steps

有关JVM钩子的更多信息,请参见:> https://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/

More on JVM hooks here: https://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/

这篇关于在黄瓜套件之前/之后如何运行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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