Tôi đang sử dụng SpecFlow với Nunit và tôi đang cố gắng thiết lập các thử nghiệm môi trường của mình bằng cách sử dụng TestFixtureSetUpAttribute, nhưng nó không bao giờ được gọi.Luồng dữ liệu với NUnit không tôn trọng TestFixtureSetUpAttribute
Tôi đã cố gắng sử dụng thuộc tính MSTests và ClassInitialize, nhưng điều tương tự cũng xảy ra. Hàm không được gọi.
Mọi ý tưởng Tại sao?
[Binding]
public class UsersCRUDSteps
{
[NUnit.Framework.TestFixtureSetUpAttribute()]
public virtual void TestInitialize()
{
// THIS FUNCTION IS NEVER CALLER
ObjectFactory.Initialize(x =>
{
x.For<IDateTimeService>().Use<DateTimeService>();
});
throw new Exception("BBB");
}
private string username, password;
[Given(@"I have entered username ""(.*)"" and password ""(.*)""")]
public void GivenIHaveEnteredUsernameAndPassword(string username, string password)
{
this.username = username;
this.password = password;
}
[When(@"I press register")]
public void WhenIPressRegister()
{
}
[Then(@"the result should be default account created")]
public void ThenTheResultShouldBeDefaultAccountCreated()
{
}
Giải pháp:
[Binding]
public class UsersCRUDSteps
{
[BeforeFeature]
public static void TestInitialize()
{
// THIS FUNCTION IS NEVER CALLER
ObjectFactory.Initialize(x =>
{
x.For<IDateTimeService>().Use<DateTimeService>();
});
throw new Exception("BBB");
}
private string username, password;
[Given(@"I have entered username ""(.*)"" and password ""(.*)""")]
public void GivenIHaveEnteredUsernameAndPassword(string username, string password)
{
this.username = username;
this.password = password;
}
[When(@"I press register")]
public void WhenIPressRegister()
{
}
[Then(@"the result should be default account created")]
public void ThenTheResultShouldBeDefaultAccountCreated()
{
}
Cảm ơn bạn, nó hoạt động. Tôi chỉ cần thay đổi chức năng của mình thành tĩnh – muek