What would be an alternate to [TearDown] and [SetUp] in MSTest?

C#SeleniumAutomated TestsMstest

C# Problem Overview


When I use MSTest Framework, and copy the code that Selenium IDE generated for me, MSTest doesn't recognize [TearDown] and [SetUp]. What is the alternative to this?

C# Solutions


Solution 1 - C#

You would use [TestCleanup] and [TestInitialize] respectively.

Solution 2 - C#

Keep in mind that your Initialize/Cleanup methods have to use the right signature.

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() {}

Solution 3 - C#

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

Solution 4 - C#

You can use [TestInitialize] for [SetUp] and [TestCleanup] for [TearDown].

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMayaView Question on Stackoverflow
Solution 1 - C#TejsView Answer on Stackoverflow
Solution 2 - C#DunkenView Answer on Stackoverflow
Solution 3 - C#John GardnerView Answer on Stackoverflow
Solution 4 - C#Mohsin AwanView Answer on Stackoverflow