我有以下代码段
public class BaseSteps : Steps
{
[BeforeFeature]
public static BeforeFeatureStep()
{
var otherStep = new OtherStep();
otherStep.ExecuteStep();
}
}
public class OtherStep : Steps
{
[Given("I save (.*) against (.*)]
public void ExecuteStep(string val, string key)
{
this.FeatureContext.Add(key, val);
}
}
功能文件1
Scenario: S1
Given I save 10 against A
Scenario: S2
Given I save 20 against B
功能文件2
Scenario: S3
Given I save 30 against C
现在,测试顺序由测试运行员确定并且是偶然的。 因此,如果场景的执行顺序是S1 - > S3 - > S2,我不能在场景S2的特征上下文中访问场景S1中保存的键值对(因为两者都属于同一个特征)?
我同意场景应该是独立的,但我的要求需要我为每个功能做一些设置,如果已经完成,请跳过它。使用上述方法我无法做到这一点,因为方案S1中的特征上下文中保存的键值对在方案S2中不可用
答案 0 :(得分:0)
I agree that scenarios should be independent, but my requirement needs me to do some setup per feature and if already done, skip it.
This should be handled by your Given
so you don't need to worry about that from the Scenario's perspective. Any setup common to all three scenarios should go in a Background
:
Background:
Given I save 10 against A
Scenario: S1
When...
Then...
Scenario: S2
Given I save 20 against B
When...
Then...
Scenario: S3
Given I save 20 against B
And I save 30 against C
When...
Then...
The step definition for "Given I save X against Y" should contain the code necessary to check for the condition, and then not apply it again.