如果我有:
[TestFixture]
public class BaseTestFixture
{
[TestFixtureSetup]
public void SetUpStuff()
{
}
}
[TestFixture]
public class DeriveTestFixture : BaseTextFixture
{
[TestFixtureSetup]
public void SetupOtherStuff()
{
}
}
在DerivedTestFixture TestFixtureSetUp方法之前或之后是否调用BaseTextFixture TestFixtureSetup方法?
答案 0 :(得分:1)
为什么不通过测试向自己证明?
[TestFixture]
public class BaseTestFixture
{
[TestFixtureSetup]
public void SetUpStuff()
{
Console.Writeline("Base");
}
}
[TestFixture]
public class DeriveTestFixture : BaseTextFixture
{
[TestFixtureSetup]
public void SetupOtherStuff()
{
Console.Writeline("Derived");
}
}
那说你可能会考虑只在基础上拥有属性并且有两个其他函数来覆盖,比如OnAfterTestFixtureSetup(),所以它更明确。也就是说,
[TestFixture]
public class BaseTextFixture
{
[TestFixtureSetup]
public void SetUpStuff()
{
Console.Writeline("Base");
OnAfterTextFixtureSetup();
}
public virtual OnAfterTextFixtureSetup()
{
}
}