我编写了一些我希望在一系列specflow测试之前执行的代码,以设置所有测试都需要的各种全局变量:
namespace MyProject.IntegrationTest
{
public static class Global
{
public static Dictionary<string, string> ContextProperties { get; set; }
[BeforeTestRun]
public static void TestInitialize()
{
// code to populate ContextProperties
var baseUrl = Global.ContextProperties["baseUrl"];
if (baseUrl.Contains("//localhost"))
{
// It's our responsibility to make sure the service is running
// TODO start iis express for the service
}
// etc
}
}
}
但是,此代码未执行。我已确保将BeforeTestRun
放在static
方法上,正如文档所述,那么出了什么问题?
答案 0 :(得分:2)
BeforeTestRun
- 装饰方法只会在specflow 中注意到,如果它位于Binding
- 装饰类中。据我所知,文档中没有明确说明这一点。
简单地向您的班级添加Binding
属性:
namespace MyProject.IntegrationTest
{
[Binding] // <==================== here
public static class Global
{
,您的BeforeTestRun
方法将根据需要进行调用。