gpt4 book ai didi

java - 为什么cucumber在所有胶水代码文件中运行@Before

转载 作者:行者123 更新时间:2023-11-30 03:16:31 25 4
gpt4 key购买 nike

我的 cucumber 测试有问题。它运行 @Before 方法所有胶水类别。

例如。该功能文件在 MainStepDef.class 中有一个粘合代码。

#language: en
@run
Feature: Testing a feature
Test before method

Background:
Given stuff is created

Scenario: The test
When i do stuff
Then stuff will be done

MainStepDef:

public class MainStepDef {

@Before
public void setup() {
System.out.println("This is OK!");
}

@Given("^stuff is created$")
public void stuff_is_created() throws Throwable {
}

@When("^i do stuff$")
public void i_do_stuff() throws Throwable {
}

@Then("^stuff will be done$")
public void stuff_will_be_done() throws Throwable {
}

}

我有一个额外的粘合文件,名为:OtherStep.class

public class OtherStepDef {

@Before
public void setup() {
throw new RuntimeException("No! Bad code! BAD CODE!");
}

@Given("^some other stuff is also created$")
public void some_other_stuff_is_also_created() throws Throwable {
}
}

终于我有了运行类(class)。

@RunWith(Cucumber.class)
@CucumberOptions(strict = true, tags = {"@run", "~@ignore" },
format = {"html:target/systemtest", "pretty" }, features = "classpath:features/",
glue = {"com.sorkmos.stepdef" }, monochrome = true)
public class RunFeatures {

}

当我运行此命令时,我从 OtherStepDef 设置方法中收到运行时异常。

为什么会发生这种情况?它不应该只执行该功能所需的粘合吗?

示例项目: https://github.com/cannibalcow/cucumberproblem

最佳答案

这是 Cucumber 的预期行为:https://groups.google.com/forum/#!topic/cukes/7gILvMsE2Js

This is the intended behaviour of the @Before and @After hooks: they are not related to each step definition. Every hook is run on each scenario (unless it's filtered out by tags).

关于java - 为什么cucumber在所有胶水代码文件中运行@Before,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32434284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com