【发布时间】:2012-02-22 06:25:31
【问题描述】:
我有一些看起来像这样的 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 |
有没有人有更好的方法来参数化诸如“做”、“不做”、“应该”、“不应该”、“有”、“没有”之类的概念?在这一点上,我正在考虑将所有内容保留为不同的场景,因为它更具可读性。
【问题讨论】:
-
你目前有 10 个测试...这似乎并不多,除非测试本身有很多步骤 - 如果它们确实有很多繁琐的步骤,我们也许可以按摩测试成形,以便表格和场景大纲变得多余。您能否发布一个实际测试作为示例(最复杂的测试?),并强调变体测试中发生变化的事情?