253

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
  • 5,592
  • 3
  • 33
  • 56
Maya
  • 6,525
  • 11
  • 39
  • 51

4 Answers4

293

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

Tejs
  • 38,896
  • 8
  • 64
  • 81
279

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
  • 7,909
  • 4
  • 51
  • 76
106

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

John Gardner
  • 22,129
  • 5
  • 55
  • 74
10

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

Mohsin Awan
  • 1,148
  • 2
  • 10
  • 28