Coder Perfect

In MSTest, what would be an alternative to [TearDown] and [SetUp]?

Problem

MSTest Framework does not recognize [TearDown] and [SetUp] when I use MSTest Framework and copy the code that Selenium IDE provided for me. What other options do you have?

Asked by Maya

Solution #1

You’d use [TestCleanup] and [TestInitialize] to clean up and initialize your tests, respectively.

Answered by Tejs

Solution #2

Remember to utilize the correct signature in your Initialize/Cleanup procedures.

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.classinitializeattribute.aspx

    [AssemblyInitialize()]
    public static void AssemblyInit(TestContext context) {}

    [ClassInitialize()]
    public static void ClassInit(TestContext context) {}

    [TestInitialize()]
    public void Initialize() {}

    [TestCleanup()]
    public void Cleanup() {}

    [ClassCleanup()]
    public static void ClassCleanup() {}

    [AssemblyCleanup()]
    public static void AssemblyCleanup() {}

Answered by Dunken

Solution #3

At the individual test level, [TestInitialize] and [TestCleanup], and at the class level, [ClassInitialize] and [ClassCleanup].

Answered by John Gardner

Solution #4

For [SetUp] and [TearDown], you can use [TestInitialize] and [TestCleanup].

Answered by Mohsin Awan

Post is based on https://stackoverflow.com/questions/6193744/what-would-be-an-alternate-to-teardown-and-setup-in-mstest