【发布时间】:2018-09-20 08:08:33
【问题描述】:
我有一个名为“RollbackManager”的类,它用于从测试中添加一些操作并在测试后执行所有操作。
我使用 SpecFlow 进行测试,因此为了在测试后执行某些操作,我使用 [AfterScenario] 钩子。
问题是:当我并行运行测试时,我不能使RollbackManager 成为静态的!
问题是:如何从挂钩访问在 SpecFlow 步骤定义中创建的 RollBackManager 类的实例?
我目前的项目结构:
带有 RollbackManager 的基类:
public class StepBase : Steps
{
public RollbackManager RollbackManager { get; } = new RollbackManager();
protected new ScenarioContext ScenarioContext { get; set; }
public StepBase(ScenarioContext scenarioContext)
{
RollbackManager = new RollbackManager();
}
}
步骤定义类示例:
[Binding]
public sealed class ThenExport : StepBase
{
public ThenExport(ScenarioContext scenarioContext) : base(scenarioContext)
{
}
[Then(@"export status should contain entities: ""(.*)""")]
public void ThenExportStatusShouldContain(List<String> commaSeparatedList)
{
RollbackManager.RegisterRollback(() => Console.WriteLine());
}
}
我的班级有钩子:
[Binding]
public sealed class SpecFlowTestsBase
{
[AfterScenario]
public void AfterScenario()
{
// here I need my rollbacks craeted in steps
}
}
【问题讨论】:
标签: automated-tests ui-automation specflow