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?
Asked
Active
Viewed 9.2k times
260
Marcos Dimitrio
- 6,100
- 4
- 35
- 59
Maya
- 6,845
- 11
- 40
- 52
-
1Why do we have to always invent some new naming for the same old stuff? – safkan May 01 '21 at 16:04
4 Answers
286
Keep in mind that your Initialize/Cleanup methods have to use the right signature.
[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
-
9+1 for AssemblyInitialize and AssemblyCleanup not mentioned here http://stackoverflow.com/a/1873572/864201 – Rodolpho Brock Jun 23 '15 at 23:07
-
@dunken Do we know TestCleanup() is executed even the test case execution fails in between? – kjosh Apr 28 '20 at 18:27
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].
Rick the Scapegoat
- 986
- 8
- 19
Mohsin Awan
- 1,156
- 2
- 12
- 29