1

I have couple of test cases (test1.cs, test2.cs, test3.cs). Each test class needs a classinitialize and classcleanup. Is it possible to move these two methods to a base class?

Example:

[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
    {
        ...
    }
}

I have tried to move these two method under an abstract class and Test1 class inherit the base class TestBase. Example: public class Test1 : TestBase. But still not working. Any idea how to make this work?

public abstract class TestBase
{
    [ClassInitialize]
    public static void ClassInitialize(TestContext __)
    {
        Launch();
    }

    [ClassCleanup]
    public static void ClassCleanup()
    {
        TearDown()
    }
}
Jason
  • 1,680
  • 3
  • 13
  • 16

0 Answers0