TestInitialize
and TestCleanup
are ran before and after each test, this is to ensure that no tests are coupled.
If you want to run methods before and after ALL tests, decorate relevant methods with the ClassInitialize
and ClassCleanup
attributes.
Relevant information from the auto generated test-file in Visual Studio:
You can use the following additional attributes as you write your tests:
// Use ClassInitialize to run code before running the first test in the class
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext) { }
// Use ClassCleanup to run code after all tests in a class have run
[ClassCleanup()]
public static void MyClassCleanup() { }
// Use TestInitialize to run code before running each test
[TestInitialize()]
public void MyTestInitialize() { }
// Use TestCleanup to run code after each test has run
[TestCleanup()]
public void MyTestCleanup() { }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…