Cucumber how to find if a feature file has executed? Any Java method?

穿精又带淫゛_ 提交于 2019-12-04 05:03:00

问题


 @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.");
  }

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.


回答1:


Cucumber scenarios should not be dependent on each other.

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.



来源:https://stackoverflow.com/questions/38336803/cucumber-how-to-find-if-a-feature-file-has-executed-any-java-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!