Dav*_*lli 27 java cucumber cucumber-jvm
我想为每个特定的功能文件指定某些设置和拆除步骤.我已经看到了允许代码在每个场景之前执行的钩子,并且钩子在每个功能之前执行代码,但我想指定在一个特定功能运行所有场景之前和之后运行一次的代码.
这可能吗?
Wou*_*ter 17
如果您使用junit来运行测试.我们使用注释来创建单元测试类和单独的步骤类.标准的@Before东西在steps类中,但@BeforeClass注释可以在主单元测试类中使用:
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"json", "<the report file"},
features = {"<the feature file>"},
strict = false,
glue = {"<package with steps classes"})
public class SomeTestIT {
@BeforeClass
public static void setUp(){
...
}
@AfterClass
public static void tearDown(){
...
}
}
Run Code Online (Sandbox Code Playgroud)
Oh *_*oon 14
你用的是黄瓜-jvm吗?我发现了一篇符合您要求的文章.
http://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/
基本上,不要使用JUnit @BeforeClass和@AfterClass,因为他们不知道Cucumber Hook标签.您是否希望Init和Teardown方法仅适用于某些场景?
尝试这个 :
在功能文件中:
@tagToIdentifyThatBeginAfterShouldRunForThisFeatureOnly
Feature : My new feature ....
Run Code Online (Sandbox Code Playgroud)
在 Stepdefinitions.java 中:
@Before("@tagToIdentifyThatBeginAfterShouldRunForThisFeatureOnly")
public void testStart() throws Throwable {
}
@After("@tagToIdentifyThatBeginAfterShouldRunForThisFeatureOnly")
public void testStart() throws Throwable {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
81207 次 |
| 最近记录: |