我有以下代码:
File1.cs 包含:
namespace TestsNM
{
[SetUpFixture]
public class MySetUpClass
{
[SetUp]
public void RunBeforeAnyTests()
{
//....
}
[TearDown]
public void RunAfterAnyTests()
{
//...
}
}
}
File2.cs 包含:
namespace TestsNM
{
[TestFixture]
public class LoginTest : MySetUpClass
{
[Test]
public void LoginInValid()
{
//...
}
[Test]
public void LoginValid()
{
//...
}
}
}
File3.cs 包含:
namespace TestsNM
{
[TestFixture]
public class AddTest : MySetUpClass
{
[Test]
public void Execute1()
{
//...
}
[Test]
public void Execute2()
{
//...
}
}
}
File4.cs 包含:
namespace TestsNM
{
public class Tests
{
[Suite]
public static IEnumerable Suite
{
get
{
return GetSuite();
}
}
static ArrayList GetSuite()
{
ArrayList suite = new ArrayList();
suite.Add(new LoginTest());
suite.Add(new AddTest());
return suite;
}
}
}
在 Main() 中:
string[] my_args = { "/fixture=" + typeof(Tests), Assembly.GetExecutingAssembly().Location };
int returnCode = NUnit.ConsoleRunner.Runner.Main(my_args);
当我运行它时,MySetUpClass 会在每次测试之前和之后执行。我怎样才能让该类在所有 TestFixtures 之前和之后只运行一次?