【发布时间】:2019-02-28 18:30:00
【问题描述】:
我需要关于如何编写场景的建议。首先我必须解释一下,我们有一个 CQRS 架构,其中命令和查询是分开的 API。我们在 Specflow 中使用 Gherkin 场景指定命令来创建测试。
在下面的场景中,域是费用。费用包是费用的集合。在这种情况下,我想指定并测试我不能为其他人创建的费用包创建费用。我只能为自己创建的费用包创建费用。
下面的做法是我尽量重用步骤:
Background:
Given I am declarant 'Marieke'
Scenario: Not allowed to create expense for a bundle that was created by another declarant
Given the following expense bundles exist
| declarant | name | administration | status |
| Lucy | Trip to New York | Company B.V. | not submitted |
When I create an expense for the following expense bundle
| declarant | name | administration | status |
| Lucy | Trip to New York | Company B.V. | not submitted |
Then the expense is not created for the expense bundle
名称、管理和状态可能与上述示例无关。但在其他情况下,我可以重用“假设存在以下费用包”步骤。这为开发人员节省了时间。
在下面的方法中,我尝试编写一个可读性更好、更具体的场景:
Background:
Given I am declarant 'Marieke'
Scenario: Not allowed to create expense for a bundle that was created by another declarant
When I create an expense for an expense bundle that was created by another declarant
Then the expense is not created for the expense bundle
在这种情况下,开发人员必须编写一个可能永远不会再次使用的 When 步骤。这是个问题吗?
在我的场景中,我在这两种选择上都苦苦挣扎。有什么建议吗?
【问题讨论】: