Java 黄瓜的失败很快

Java 黄瓜的失败很快,java,cucumber,Java,Cucumber,我们正在使用基于Java的Cucumber项目 想知道是否有快速故障选项。 如果我运行10个场景&如果第二个测试失败,我的测试应该在第二个场景之后停止 static boolean prevScenarioFailed = false; @Before public void teardown(Scenario scenario) throws Exception { prevScenarioFailed = scenario.isFailed();

我们正在使用基于Java的Cucumber项目

想知道是否有快速故障选项。 如果我运行10个场景&如果第二个测试失败,我的测试应该在第二个场景之后停止

static boolean prevScenarioFailed = false;
  @Before
    public void teardown(Scenario scenario) throws Exception {
        prevScenarioFailed = scenario.isFailed();
        if(env.getProperty("fail_fast").toString().equalsIgnoreCase( "true")) {
            if (prevScenarioFailed) {

                throw new RuntimeException("Fail!");
            }

        }
    }

我假设跑步者在junit中

案例1-在特定场景失败后跳过所有场景。

private static int skipCount = 0;
private static final int ALLOWED_FAIL_TEST_COUNT = 2;

@Before
public void beforeSkipCount() {
    if(skipCount == ALLOWED_FAIL_TEST_COUNT)
        Assume.assumeTrue(false);
}

@After
public void afterSkipCount(Scenario scen) {
    if(scen.isFailed())
        skipCount++;
}
在功能文件中要在发生故障时快速失败的场景上使用特定标记,如(
@SkipCheck

步骤定义或钩子类中添加以下内容

    private static boolean skipFlag = false;

    @Before
    public void beforeSkipCount() {
        if(skipFlag)
            Assume.assumeTrue(false);
    }

    @After
    public void afterSkipCount(Scenario scen) {
        if(scen.getSourceTagNames().contains("@SkipCheck") && scen.isFailed())
            skipFlag = true;
    }
案例2-在特定场景计数失败后跳过所有场景。

private static int skipCount = 0;
private static final int ALLOWED_FAIL_TEST_COUNT = 2;

@Before
public void beforeSkipCount() {
    if(skipCount == ALLOWED_FAIL_TEST_COUNT)
        Assume.assumeTrue(false);
}

@After
public void afterSkipCount(Scenario scen) {
    if(scen.isFailed())
        skipCount++;
}

如果项目中有多个运行者,并且希望跳过其中的场景,则需要将
Before
hook的内容复制到junit
BeforeClass
hook。相应地更改标志的访问权限。

我假设跑步者在junit中

案例1-在特定场景失败后跳过所有场景。

private static int skipCount = 0;
private static final int ALLOWED_FAIL_TEST_COUNT = 2;

@Before
public void beforeSkipCount() {
    if(skipCount == ALLOWED_FAIL_TEST_COUNT)
        Assume.assumeTrue(false);
}

@After
public void afterSkipCount(Scenario scen) {
    if(scen.isFailed())
        skipCount++;
}
在功能文件中要在发生故障时快速失败的场景上使用特定标记,如(
@SkipCheck

步骤定义或钩子类中添加以下内容

    private static boolean skipFlag = false;

    @Before
    public void beforeSkipCount() {
        if(skipFlag)
            Assume.assumeTrue(false);
    }

    @After
    public void afterSkipCount(Scenario scen) {
        if(scen.getSourceTagNames().contains("@SkipCheck") && scen.isFailed())
            skipFlag = true;
    }
案例2-在特定场景计数失败后跳过所有场景。

private static int skipCount = 0;
private static final int ALLOWED_FAIL_TEST_COUNT = 2;

@Before
public void beforeSkipCount() {
    if(skipCount == ALLOWED_FAIL_TEST_COUNT)
        Assume.assumeTrue(false);
}

@After
public void afterSkipCount(Scenario scen) {
    if(scen.isFailed())
        skipCount++;
}
如果项目中有多个运行者,并且希望跳过其中的场景,则需要将
Before
hook的内容复制到junit
BeforeClass
hook。相应地更改标志的访问权限。

可能重复的可能重复的