我有一些看起来像这样的 specflow 测试:
Scenario: Person is new and needs an email
Given a person
And the person does not exist in the repository
When I run the new user batch job
Then the person should be sent an email
Scenario: Person is not new and needs an email
Given a person
And the person does exist in the repository
When I run the new user batch job
Then the person should not be sent an email
除了只有 2 个场景之外,我有 10 个非常相似的场景,都具有步骤类型,所以我想使用“场景大纲”。不幸的是,我很难想出一种可读的方式来重写我的步骤。
目前,我想出了这个,但看起来很笨重:
Scenario: Email batch job is run
Given a person
And the person '<personDoes/NotExist>' exist in the repository
When I run the new user batch job
Then the person '<personShould/NotGetEmail>' be sent an email
Examples:
| !notes | personDoes/NotExist | personShould/NotGetEmail |
| Exists | does not | should |
| No Exist | does | should not |
我也考虑过这一点,虽然它更干净,但它几乎没有传达意义
Scenario: Email batch job is run
Given a person
And the person does exist in the repository (is '<personExist>')
When I run the new user batch job
Then the person should be sent an email (is '<sendEmail>')
Examples:
| !notes | personExist | sendEmail |
| Exists | false | true |
| No Exist | does | false |
有没有人有更好的方法来参数化诸如“做”、“不做”、“应该”、“不应该”、“有”、“没有”之类的概念?此时,我正在考虑将所有内容保留为不同的场景,因为它更具可读性。