1、Composite Steps
顾名思义就是能够把多个Steps组合为一个Step。例子
Meta:
@author liuxianning
@theme composite
Narrative: This story is used to show composite steps.
Scenario: Add a student into the class
Given There is a student with default details
When system add the student into class
Then we can get student 'Lincoln2' from class
然后在StudentSteps中增加方法
@Given("There is a student with default details")
@Composite(steps = {
"Given his name is 'Lincoln2'",
"Given his age is '18'",
"Given his hobby is 'basketball'",
"Given his father's name is 'Mike'",
"Given his mother's name is 'Mary'",
"Given his brother's name is 'Luis'"
})
public void createStudentWithDefaultDetails() {
}
这样就可以用一句话执行之前已经实现的很多步骤。
2、Tabular parameters
表结构参数,这是一个简化和结构化参数输入的特性,我们可以在一个步骤中把需要传递的多个参数结构化的传递给Step方法。例子:
Meta:
@author liuxianning
@theme table
Narrative: In order to get a new student,as a teacher, I want to add a student into the Class
Scenario: Add a student into the class
Given There is a student with details:
|name |age |hobby |father name |mother name |brother name|
|lincoln3|18 |basketball |Mike |Mary |Luis |
When system add the student into class
Then we can get student 'lincoln3' from class
可以通过一个Table以键值对的形势来输入参数,在StudentSteps添加对应的方法来接收参数
@Given("There is a student with details:$details")
public void setDetails(@Named("details") ExamplesTable details) {
student = new Student();
Parameters parameters = details.getRowAsParameters(0);
student.setName(parameters.valueAs("name",String.class));
student.setAge(parameters.valueAs("age",Integer.class));
student.setHobby(parameters.valueAs("hobby",String.class));
student.setFatherName(parameters.valueAs("father name",String.class));
student.setMotherName(parameters.valueAs("mother name",String.class));
student.setBrotherName(parameters.valueAs("brother name",String.class));
}
3、Examples
Scenario多实例,这个特性主要的目的在于可以使用不同的数据反复执行一个Scenario。例子:
Meta:
@author liuxianning
@theme examples
Narrative: In order to get a new student,as a teacher, I want to add a student into the Class
Scenario: Add a student into the class
Given There is a student
And his name is '$name'
And his age is '$age'
When system add the student into class
Then we can get student '$studentName' from class
Examples:
|name|age|studentName|
|lxn1|18 |lxn1 |
|lxn2|19 |lxn2 |
|lxn3|20 |lxn3 |
该实例中回使用Examples中的数据反复执行该Scenario。
4、Meta Filtering
Meta信息过滤,这个特性允许JBehave指定运行特定的Story或者Scenario。使用方法为在配置Embedder的时候添加上MetaFilter属性。
public Embedder configuredEmbedder() {
Embedder embedder = new Embedder();
embedder.useConfiguration(configuration());
embedder.useCandidateSteps(candidateSteps());
embedder.useStepsFactory(stepsFactory());
[color=red] embedder.useMetaFilters(asList("+theme composite", "-skip"));[/color]
return embedder;
}
在标红的代码段中指明了只执行Meta段中属性theme为composite的Story。
5、GivenStories
Story依赖,这个特性让一个Story可以作为另一个Story的Scenario的前提条件。例子
Meta:
@author liuxianning
@theme givenstories
Narrative: In order to maintian student's info,as a teacher, I want to update a student's name
Scenario: Add a student into the class
GivenStories: AddStudentIntoClass.story
Given Get student "Lincoln"
When system Update student name to "Lin"
Then we can get student 'Lin' from class
分享到:
相关推荐
jsemver.zip,semver规范的java实现semver规范的java实现
jbehave-tutorial-maste
jbehave core用于BDD Java自动化代码开发jar包
gitter-scala.zip,纯功能scala gitter api客户端纯功能gitter api客户端
jbehave4-scenario-restart 此maven项目重现了JBehave 4中的问题,并且在引发RestartingScenarioFailure Exception之后,未重新RestartingScenarioFailure Scenario。 使用JBehave 4.0.1运行 只需执行mvn clean ...
jbehave4-step-priority PerformableTree正在添加由于元过滤器而被禁止的ExamplePerformableScenario实例。 这会导致大量调用StepFinder.prioritise()方法,从而导致性能下降,尤其是在使用Levenshtein Distance时...
jbehave-spring-sample
scala-time.zip,scalaj timea joda time的scala包装器
cucumber-reporting.zip,这个项目为cucumber提供了漂亮的html报告。它的工作原理是从cucumber json生成html
jbehave-testng-example完整的入门专案与范例一个简单加法器BDD范例使用JBehave + TestNG
jbehave-bigdecimal-converter 这个maven项目演示了JBehave允许BigDecimal(NumberConverter)使用的不良用法。使用Maven运行从终端,只需执行: mvn clean install 由于java.lang.RuntimeException: ********** ...