Visual Studio Unit Testing: SetUp and TearDown

Etibar Hasanov picture Etibar Hasanov · Jan 22, 2013 · Viewed 42.4k times · Source

Instead of [SetUp] and [TearDown] in Nunit what is the alternative in Visual Studio Ultimate 2010 Unit Testing. In Nunit you can imagine setup and teardown methods are as constructors and destructors for the tests in our class.

Answer

Mikeb picture Mikeb · Jan 22, 2013

A method annotated with [TestInitialize] is run before each test. Likewise [TestCleanup] is after each test.

[ClassInitialize] and [ClassCleanup] are run before and after the 'suite' of tests inside the TestClass.