Specflow - 如何返回上一步

时间:2013-06-28 11:58:52

标签: testing bdd specflow

让我们说这是我的.feature文件,在一步之后,一个方法被绑定..

Given The system administrator sends a list of Tracks
And The system is at CreateCWRFile method
And The system sends "name", "caeID" & "ver" to generate HDR Line   
Then The system generates GRH Line
Then The system generates track Revision Line   
Then The system generates track SPU Line
Then The system generates track SPT Line
Then The system generates and verifies SWT, PWR & SWR Lines each writer of track

假设我的测试是在第5行,即第5步,在某些情况下,我想回到第2步,如何做...

1 个答案:

答案 0 :(得分:1)

冒着重复Specflow step definition mapping with wildcard attribute的风险,我认为你因为你想要达到的目标而苦苦挣扎。

SpecFlow善于描述;

  • 您的系统应处于的状态 - 即Given
  • 您要执行的操作 - 即When
  • 以及之后的州应该是什么样的,Then

因此,上面的示例可能会混淆ThenWhen的某些内容。

正如nemesv在评论中指出的那样,您可能应该有多个方案来处理分支。请查看How to run gherkin scenario multiple times示例。

您唯一的另一个选择是从多个步骤构建您的场景,并且每次测试您处于正确的状态,例如

Given the traffic light is red
When the light changes
Then the light should be amber
When the light changes
Then the light should be green
When the light changes
Then the light should be amber
When the light changes
Then the light should be red
祝你好运: - )