黄瓜如何查找功能文件是否已执行?任何Java方法? [英] Cucumber how to find if a feature file has executed? Any Java method?

查看:164
本文介绍了黄瓜如何查找功能文件是否已执行?任何Java方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 @Before
  public void quit_if_tagged_scenario_failed(Scenario scenario) {
    if (!isTagged(scenario) && prevScenarioFailed)
      throw new IllegalStateException("An important scenario has failed!     Cucumber wants to quit.");
  }



我使用这种方法来检查previuos场景是否失败。如果失败,我想跳过该功能文件中的所有情况。因此,问题是,如果我运行两个功能文件,功能文件中的最后一个方案失败,下一个功能的第一步也将失败,因为黄瓜以前的方案过去特征文件失败。你知道如何处理这种情况吗?
您的帮助将非常感谢。

I'm using this method to check if the previuos scenario failed. If failed I want to skip all the scenarios in that feature file.So the problem here is if I’m running two feature files the last scenario in the feature file failed and the first step of next feature will also fails because cucumbers previous scenario from past feature file is failed. Do you know how to handle that kind of situation? Your help will be greatly appreciated.

推荐答案

如前所述,Cucumber方案不应该依赖于彼此。

As mentioned here, Cucumber scenarios should not be dependent on each other.

根据Cucumber最佳实践,不应该有任何场景之间的耦合。或者换句话说,在情境之间应该没有持续的状态。

According to the Cucumber best practices, there shouldn’t be any sort of coupling between scenarios. Or in other words, there should be no state that persists between scenarios.

仅仅作为一个例子,为什么这是一个坏的做法考虑一种情况下一个方案步骤添加一个记录到数据库,而后续方案取决于该记录的存在。这可能有效,但如果方案运行的顺序发生改变或并行运行,则会产生问题。

Just as an example why this is a bad practice consider a case when one scenario step adds a record to a database, while the subsequent scenarios depend on the existence of that record. This may work, but will create a problem if the order in which scenarios run changes, or they are run in parallel.

尝试检查您的方法,看看如何以不同的方式定义您的场景,以避免耦合。祝你好运。

Try to review your approach and see how can you define your scenarios differently to avoid coupling. Good luck.

这篇关于黄瓜如何查找功能文件是否已执行?任何Java方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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