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 8.8k times
253
![](../../users/profiles/4306798.webp)
Marcos Dimitrio
- 5,592
- 3
- 33
- 56
![](../../users/profiles/749097.webp)
Maya
- 6,525
- 11
- 39
- 51
-
Why do we have to always invent some new naming for the same old stuff? – safkan May 01 '21 at 16:04
4 Answers
279
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() {}
![](../../users/profiles/520094.webp)
Dunken
- 7,909
- 4
- 51
- 76
-
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.
![](../../users/profiles/13687.webp)
John Gardner
- 22,129
- 5
- 55
- 74
10
You can use [TestInitialize]
for [SetUp]
and [TestCleanup]
for [TearDown]
.
![](../../users/profiles/3735683.webp)
Rick the Scapegoat
- 878
- 7
- 18
![](../../users/profiles/6852301.webp)
Mohsin Awan
- 1,148
- 2
- 10
- 28