我的黄瓜测试有问题。它运行@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 {
}
}
最后我有我的跑步者班。
@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
安装方法获取运行时异常。
为什么会这样?它是否应该只执行该功能所需的胶水?
答案 0 :(得分:2)
这是Cucumber的预期行为:https://groups.google.com/forum/#!topic/cukes/7gILvMsE2Js
这是@Before和@After钩子的预期行为:它们 与每个步骤定义无关。每个钩子都在每个钩子上运行 场景(除非它被标签过滤掉)。