JBehave学习笔记(3)--高级特性介绍
1、Composite Steps
顾名思义就是能够把多个Steps组合为一个Step。例子
Meta:@author liuxianning@theme compositeNarrative: This story is used to show composite steps.Scenario: Add a student into the classGiven There is a student with default detailsWhen system add the student into classThen we can get student 'Lincoln2' from class
@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() { }
Meta:@author liuxianning@theme tableNarrative: In order to get a new student,as a teacher, I want to add a student into the ClassScenario: Add a student into the classGiven 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 classThen we can get student 'lincoln3' from class
@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)); }
Meta:@author liuxianning@theme examplesNarrative: In order to get a new student,as a teacher, I want to add a student into the ClassScenario: Add a student into the classGiven There is a studentAnd his name is '$name'And his age is '$age'When system add the student into classThen we can get student '$studentName' from classExamples:|name|age|studentName||lxn1|18 |lxn1 ||lxn2|19 |lxn2 ||lxn3|20 |lxn3 |
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:@author liuxianning@theme givenstoriesNarrative: In order to maintian student's info,as a teacher, I want to update a student's nameScenario: Add a student into the classGivenStories: AddStudentIntoClass.storyGiven Get student "Lincoln"When system Update student name to "Lin"Then we can get student 'Lin' from class