Den*_*men 7 bdd acceptance-testing cucumber specflow gherkin
我想我完全理解SpecFlow背后的概念和想法,但即使阅读了Secret Ninja Cucumber Scrolls,The Cucumber Book,并且经历了各种论坛,我仍然不确定可重用性的途径.
我们的方案已经符合各种指南
我们的步骤必须遵守以下准则(一些特定于SpecFlow):
但即使我们使用正则表达式占位符,我们仍然会得到相同步骤的大量变体.特别是如果某些事情不重要,你就不应该提到这些变化的规则.是的,在内部这些步骤重复使用,但不在场景中.
考虑例如以下场景:
Feature: Signing where both persons are physically available
@Smoke
Scenario: Show remaining time to sign based on previous signature
Given a draft proposal
And the first signature has been set
When I try to set the second signature
Then the remaining time to sign should be shown
@Smoke
Scenario: Re-signing of the first proposal
Given a signature that has not been set within the configured time
And the first signature has just been re-signed
When I try to set the second signature
Then the remaining time should start over
Run Code Online (Sandbox Code Playgroud)
将两个"给定"步骤合并为一个并放松一些可重用性会更好吗?
其他一些例子:
Feature: Conditionally show signatures to be signed
@Smoke
Scenario: Show the correct signature for a proposal with a night shift
Given I have a proposal for the day shift
When I change it to the night shift
Then I should only be able to sign for the night shift
@Smoke
Scenario: Show additional signature when extending the shift
Given I have a suspended proposal for the night shift
When I extend the period to the day shift
Then I should confirm extening the period over the shift
Run Code Online (Sandbox Code Playgroud)
我在这里错过了一个基本概念吗?
Gas*_*agy 12
这不是答案,而是一些提示:
你需要一个类来代表带有装饰的测试中的许可证:
class PermitDescription{
bool suspended;
bool draft;
}
Run Code Online (Sandbox Code Playgroud)
创建转换器方法:
[StepArgumentTransformation("permit")]
public PermitDescription CreateSimple(){
return new PermitDescription();
}
[StepArgumentTransformation("draft permit")]
public PermitDescription CreateDraft(){
return new PermitDescription() { draft = true; }
}
[StepArgumentTransformation("suspended permit")]
public PermitDescription CreateSuspended(){
return new PermitDescription() { suspended = true; }
}
Run Code Online (Sandbox Code Playgroud)
您现在可以获得需要许可的更灵活的步骤定义:
[Given(@"I have a (.*) for the day shift")]
public void Something(PermitDescription p)
{ ... }
Run Code Online (Sandbox Code Playgroud)
匹配到:
Given I have a permit for the day shift
Given I have a draft permit for the day shift
Given I have a suspended permit for the day shift
Run Code Online (Sandbox Code Playgroud)
当然这是一种可以滥用的工具,但在某些情况下它可以提供帮助.
| 归档时间: |
|
| 查看次数: |
3743 次 |
| 最近记录: |