Tag Archives: test

Running custom code before and after tests

if you ever wrote a unit test in Visual Studio you probably heard of the [TestClass] and [TestMethod] attributes, that you can use to annotate classes and methods which contain tests. You can use similar attributes to decorate methods, which should run before and after the tests:

Methods decorated with the TestInitialize and TestCleanup attributes are executed before and after each and every test.

Methods decorated with the ClassInitialize and ClassCleanup attributes are executed before the first test and after the last test in the current class.

Methods decorated with the AssemblyInitialize and AssemblyCleanup attributes are executed before the first test and after the last test in the current assembly.

The last two can be particularly useful if you do Continuous Integration.

 

Technorati-címkék: ,