Cucumber.wants_to_quit的黄瓜-jvm等价物是什么?

问题描述 投票:0回答:3

我正在使用Cucuming-jvm编写测试,并且我希望系统在第一个失败的方案上停止运行测试。我找到了为黄瓜Ruby编写的示例代码,该代码通过After钩子执行此操作。我正在搜索要调用的正确Java类和方法,这与在Ruby中设置Cucumber.wants_to_quit = true等效。

这是我的示例代码:

@After
public void quitOnErrors(Scenario scenario) {
    if (scenario.isFailed()) {
                    // Need the correct class/method/property to call here.
        cucumber.api.junit.Cucumber.wants_to_quit = true;   
    }
}    
cucumber-jvm
3个回答
1
投票

我找不到使用Cucumber-JVM进行本机处理的任何方法,但是您始终可以这样做:

static boolean prevScenarioFailed = false;

@Before
public void setup() throws Exception {
    if (prevScenarioFailed) {
        throw new IllegalStateException("Previous scenario failed!");
    }
    // rest of your setup
}

@After
public void teardown(Scenario scenario) throws Exception {
    prevScenarioFailed = scenario.isFailed();
    // rest of your teardown
}

0
投票

黄瓜-jvm接受的答案在第一次测试失败时退出,使用

throw new IllegalStateException()

根据我的经验,不起作用。

改为尝试黄瓜命令行开关-y

我没有找到-y的任何硬性文档,但有人建议here,并且该对话中的开发人员致力于实现它。我已经对其进行了测试,并且可以正常工作。

我没有找到Cucumber.wants_to_quit?的cucumber-jvm版本,但是也许可以涵盖您的用例。


0
投票

在场景定义失败后在步骤定义文件中创建黄瓜挂钩有助于停止测试。这涉及创建@Before@After方法。看一下这个例子:

@Before
  public void setUp() {
    if (prevScenarioFailed) {
      throw new IllegalStateException("Previous scenario failed!");
    }


  }

  @After()
  public void stopExecutionAfterFailure(Scenario scenario) {
    prevScenarioFailed = scenario.isFailed();
  }
© www.soinside.com 2019 - 2024. All rights reserved.