我是Gherking的新手,并试图尽我所能写出第一个场景,但是我经常发现自己确实很想在场景中添加“ Else”。 “给定,何时,然后,其他”变为“给定,何时,然后,其他”。我知道“ Else”关键字没有定义,因此在Gherkin工具中没有实现,但是对我来说并不重要,因为我不使用这些工具。
您认为写这个是正确的吗?
示例:
Scenario : Application starts
Given I start the application
When I already have an open session
Then I see the home screen
Else I see the login screen
还是写两个不同的场景更好?
Scenario : Application started by authenticated user
Given I have an open session
When I start the application
Then I see the home screen
Scenario : Application started by unauthenticated user
Given I don't have an open session
When I start the application
Then I see the login screen
答案 0 :(得分:1)
简而言之,不是,但是以下是处理场景的多种变体的选项:
但是从您的示例来看,所有步骤都稍有不同,因此您可以:-
或
或者(我的偏爱)
所以:
Scenario : Application started by authenticated user
Given I have an open session
When I start the application
Then I see the home screen
Scenario : Application started by unauthenticated user
Given I don't have an open session
When I start the application
Then I see the login screen
成为:
Scenario Outline: Application Start and login
Given Application started by <AuthenticationStatus> user
And I have <SessionState> session
When I start the application
Then I see the <FirstScreen> screen
Examples:
|AuthenticationStatus |SessionState |FirstScreen|
|Authenticated |open |home |
|Un-Authenticated |not open |login |
在两种情况下,恕我直言,失去可读性可能不值得,但我认为绝对值得。