Java JBehave子场景?
在一个场景(类似于子场景)中添加多个Java JBehave子场景?,java,jbehave,Java,Jbehave,在一个场景(类似于子场景)中添加多个给定的块是否可能 下面是我想到的一个例子: A sample story with a collection of scenarios Narrative: As a dev In order to do work I want multiple sub-scenarios :-) Scenario: A sample collection scenario Given step1... When step1... Then
给定的块是否可能
下面是我想到的一个例子:
A sample story with a collection of scenarios
Narrative:
As a dev
In order to do work
I want multiple sub-scenarios :-)
Scenario: A sample collection scenario
Given step1...
When step1...
Then step1...
Given step2...
When step2...
Then step2...
作为一种变通方法,我可以使用多种场景,但这需要重写一些用于初始化结构的粘合代码(在方法之前和之后)
有什么可以避免的吗?提前谢谢 是的,你可以这样做。
故事的简单例子:
A sample story with a collection of scenarios
Narrative:
As a dev
In order to do work
I want multiple sub-scenarios :-)
Scenario: A sample collection scenario
Given step 1
And step 11
When step 1
And step 11
Then step 1
And step 11
Given step 2
When step 2
Then step 2
java代码:
public class Test extends Steps {
@Given("step 1")
public void givenStep1() {
System.out.println("Given Step 1");
}
@Given("step 11")
public void givenStep11() {
System.out.println("Given Step 11");
}
@Given("step 2")
public void givenStep2() {
System.out.println("Given Step 2");
}
@When("step $step")
public void when(String step){
System.out.println("When Step " + step);
}
@Then("step $step")
public void then(String step){
System.out.println("Then Step " + step);
}
}
以及测试结果:
Running story main/resources/test.story
Given Step 1
Given Step 11
When Step 1
When Step 11
Then Step 1
Then Step 11
Given Step 2
When Step 2
Then Step 2
注意在本例中,和
关键字是如何匹配的
当和
在给定的
行下使用时,它被踩成给定的
,如果在下面,那么它被匹配为然后
关键字等。哇,谢谢!我很快就会查的!我不知道为什么它对我不起作用,让我们再给一次机会:-)