我有几个测试用例(test1.cs,test2.cs,test3.cs)。每个测试类都需要一个classinitialize
和classcleanup
。是否可以将这两种方法移至基类?
示例:
[TestClass]
public class Test1
{
[ClassInitialize]
public static void ClassInitialize(TestContext __)
{
Launch();
}
[ClassCleanup]
public static void ClassCleanup()
{
TearDown()
}
[TestMethod]
public void TestMethod1
{
...
}
}
[TestClass]
public class Test2
{
[ClassInitialize]
public static void ClassInitialize(TestContext __)
{
Launch();
}
[ClassCleanup]
public static void ClassCleanup()
{
TearDown()
}
[TestMethod]
public void TestMethod1
{
...
}
}
我试图将这两个方法移至抽象类下,而Test1
类继承了基类TestBase
。示例:public class Test1 : TestBase
。但仍然无法正常工作。知道如何进行这项工作吗?
public abstract class TestBase
{
[ClassInitialize]
public static void ClassInitialize(TestContext __)
{
Launch();
}
[ClassCleanup]
public static void ClassCleanup()
{
TearDown()
}
}