如何编写具有多种可能结果的情景

  • 本文关键字:结果 何编写 ruby gherkin
  • 更新时间 :
  • 英文 :


这是我第一次尝试写一个有多种可能结果的场景。目前的场景覆盖为快乐流。然而,由于检测到不同的状态,该场景失败。在运行时获取动态值(Pass和Failed)。

然后语句看起来像这样,这是快乐流:

Feature: Student exam score

Scenario: Check exam score for 3 students and all students pass
Given there are 3 students sit for examination
And all the student completed then exam
When teacher completed marking the exam paper
Then studentA exam score is Pass
Then studentB exam score is Pass
Then studentC exam score is Pass

实际执行可能导致以下结果组合:

1。学生a:及格,学生b:及格,学生c:不及格

2。学生a:及格,学生b:不及格,学生c:及格

Scenario: Check exam score for 3 students and 2 student pass studentB failed
Given there are 3 students sit for examination
And all the student completed then exam
When teacher completed marking the exam paper
Then studentA exam score is Pass
Then studentB exam score is Failed
Then studentC exam score is Pass

Scenario: Check exam score for 3 students and 2 student pass studentC failed
Given there are 3 students sit for examination
And all the student completed then exam
When teacher completed marking the exam paper
Then studentA exam score is Pass
Then studentB exam score is Pass
Then studentC exam score is Failed

所以目前正在寻找替代方案,什么是最好的处理这种情况与多个结果。

您必须这样编写您的场景您的特性文件

Scenario: Check exam score for 3 students
Given there are 3 students sit for examination
And all the student completed then exam
When teacher completed marking the exam paper
And student exam score is "<StudentA>"
And student exam score is "<StudentB>"
And student exam score is "<StudentC>"
Example:
|StudentA   |StudentB   |StudentC   |
|Pass       |Pass       |Pass       |
|Pass       |Failed     |Pass       |
|Pass       |Pass       |Failed     |

和你的步骤文件

@When("^student exam score is "([^"]*)"$")
public void student_exam_score_is_something(String statusStr) 
throws Throwable {
if(statusStr.equals("pass"){
// your code for passed student
}
else if(statusStr.equals("failed"){
// your code for failed student
}
}

相关内容

最新更新