在使用 SpecFlow 熟悉行为驱动开发后,我想知道是否有多个场景用于相同的功能,如下所示:
注册特征
Feature: Register a new user
In order to use the system,
one must register with the system
so that one gets authorized and may login
Scenario: Register a new user using valid credentials
Given I am on the registration page
When I have entered my desired username "UserName" and password "password"
And I have confirmed my password "password"
And I click the register button
Then I shall get confirmation that I am now a registered user
除了我的场景可能有点太胖之外,还必须设法验证注册过程中的其他场景,例如:
- 输入用户名太短
- 输入密码太短
- 输入密码不包含数字
- 输入密码与确认密码不符
仅举几个。我已经阅读了有关使用 SpecFlow 功能文件的标签,以便我可以执行以下操作:
@shorterPasswordProvided
Scenario: Register a user using a password that is too short
Given I am on the registration page
When I have entered my desired user name
And I have provided a password that is too short "allo"
And I click the Register button
Then I shall get an error message which mentions about the password minimum length
@noCredentialsAtAll
Scenario: Register a user using no credentials at all
Given I am on the registration page
When I click on the Register button with no credentials entered
Then I shall get an error message that says I have to fill all required fields in
然后,使用[BeforeScenario("myTag")]
应该做的伎俩。
钩子允许按照某些规则执行要执行的测试子集。因此,一个When
方法可以在预定义的上下文中执行,也就是说,它应该被执行的钩子,并且通过BeforeScenario
或类似的属性被提及。
我是否理解正确,还是我在这里迷茫?
我是不是推得太远了?
我错过了什么吗?
是否所有“密码太短”、“未提供凭据”都考虑了不同的使用场景,或者它们是否只能适合代码中的其他地方,比如单元测试本身?
我的意思是,所有这些场景都属于 Register 特性,因此,它们应该在同一个 Register.feature SpecFlow 特性文件中定义,对吧?