这是我们的一项验收测试的示例:
Feature: Add an effect to a level
In order to create a configuration
As a user
I want to be able to add effects to a level
Scenario: Add a new valve effect to a level
Given I have created a level named LEVEL123 with description fooDescription
And I am on the configuration page
When I click LEVEL123 in the level tree
And I expand the panel named Editor Panel
And I click the Add Valve Effect button
And the popup named ASRAddVal appears
And I click the Add new button
And I fill in these vertical fields
| field name | value |
| Name | Effect123 |
Then I should see the following texts on the screen
| text |
| Effect added : EFFECT123 |
Run Code Online (Sandbox Code Playgroud)
我们觉得这有点冗长,我们想听听你如何减少Specflow中的步骤.从我到目前为止所读到的,不推荐创建特定的不可重用步骤,那么在SpecFlow中执行此操作时被视为"最佳实践"?
更新:
我想说的是,我已经了解到你应该尝试创建通用步骤,以便在多个测试中重复使用它们.一种方法是参数化你的步骤,例如:"鉴于我已经创建了一个名为..的级别",但参数化也引入了详细程度.我想最终得到Bryan Oakley在他的回答中建议的东西,但是我不知道如何在不创建非常特定于每个测试的步骤的情况下做到这一点.这再次意味着我最终会采取许多措施来降低可维护性.我看起来SpecFlow有一些通过创建一个继承称为"Steps"的基类的文件来定义缩写步骤的方法,但这仍然引入了新的步骤.
总结一下事情; 告诉我一个很好的方法来结束可以维持的Bryan Oakleys答案.
我会简化它到这样的事情:
Scenario: Add a new valve effect to a level
Given I have created a new level
When I add a new valve effect with the following values
| field name | value |
| Name | Effect123 |
Then I should get an on-screen confirmation that says "Effect added: Effect123"
Run Code Online (Sandbox Code Playgroud)
我解决问题的方法是想象你正在完全重新设计用户界面.测试仍然可用吗?例如,即使重新设计中没有"添加"按钮,或者您不再使用弹出窗口,测试也应该有效.
| 归档时间: |
|
| 查看次数: |
1287 次 |
| 最近记录: |