You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running multiple [TestClass]es at the same time, why does the [ClassCleanup()] methods only get called at the very end?
File: UnitTest1.cs
[TestClass]
public class UnitTest1
{
[ClassInitialize()]
public static void ClassInit(TestContext context) { }
[ClassCleanup()]
public static void ClassCleanup() { }
[TestMethod]
public void TestMethod() { }
}
File: UnitTest2.cs
[TestClass]
public class UnitTest2
{
[ClassInitialize()]
public static void ClassInit(TestContext context) { }
[ClassCleanup()]
public static void ClassCleanup() { }
[TestMethod]
public void TestMethod() { }
}
The execution order is the following:
UnitTest2.ClassInit()
UnitTest2.TestMethod()
UnitTest1.ClassInit()
UnitTest1.TestMethod()
UnitTest2.ClassCleanup()
UnitTest1.ClassCleanup()
Notice that both [ClassCleanup] methods are executed at the end of the set; not after each TestClass is "done".
But I expected a different behavior:
UnitTest2.ClassInit()
UnitTest2.TestMethod()
UnitTest2.ClassCleanup() - Expected
UnitTest1.ClassInit()
UnitTest1.TestMethod()
UnitTest1.ClassCleanup() - Expected
Microsoft's Documentation - ClassCleanupAttribute Class says, "Identifies a method that contains code to be used after all the tests in the test class have run and to free resources obtained by the test class."
But it appears to be run/executed late, after ALL tests have run. This seems wrong, and it is blocking my development.
The text was updated successfully, but these errors were encountered:
Hey folks. This is a super confusing behavior of MSTest! Basically ClassCleanup default mode is equivalent to AssemblyCleanup and is run only after the last test of the run. There is a property you can use to change this [ClassCleanup(ClassCleanupBehavior.EndOfClass)].
Note that we are planning to change the default in the next major release of MSTest (after v3), see #1316
When running multiple [TestClass]es at the same time, why does the [ClassCleanup()] methods only get called at the very end?
File: UnitTest1.cs
[TestClass]
public class UnitTest1
{
[ClassInitialize()]
public static void ClassInit(TestContext context) { }
[ClassCleanup()]
public static void ClassCleanup() { }
[TestMethod]
public void TestMethod() { }
}
File: UnitTest2.cs
[TestClass]
public class UnitTest2
{
[ClassInitialize()]
public static void ClassInit(TestContext context) { }
[ClassCleanup()]
public static void ClassCleanup() { }
[TestMethod]
public void TestMethod() { }
}
The execution order is the following:
Notice that both [ClassCleanup] methods are executed at the end of the set; not after each TestClass is "done".
But I expected a different behavior:
Microsoft's Documentation - ClassCleanupAttribute Class says, "Identifies a method that contains code to be used after all the tests in the test class have run and to free resources obtained by the test class."
But it appears to be run/executed late, after ALL tests have run. This seems wrong, and it is blocking my development.
The text was updated successfully, but these errors were encountered: