I've written code that I want executed before a run of specflow tests, to set up various globals that all the tests will need:
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
}
}
}
However, this code isn't being executed. I've made sure to put BeforeTestRun
on a static
method, as the documentation says to, so what's wrong?
The BeforeTestRun
-decorated method will only be noticed by specflow if it's in a Binding
-decorated class. As far as I can see this isn't explciitly called out in the documentation.
Simple add a Binding
attribute to your class:
namespace MyProject.IntegrationTest
{
[Binding] // <==================== here
public static class Global
{
and your BeforeTestRun
method will be called as desired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With