260

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?

Marcos Dimitrio
  • 6,100
  • 4
  • 35
  • 59
Maya
  • 6,845
  • 11
  • 40
  • 52

4 Answers4

305

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

Tejs
  • 39,976
  • 10
  • 65
  • 85
286

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() {}
Dunken
  • 8,143
  • 4
  • 53
  • 83
106

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

John Gardner
  • 23,084
  • 5
  • 57
  • 75
10

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

Mohsin Awan
  • 1,156
  • 2
  • 12
  • 29