Unit-testing frameworks such as NUnit and Microsoft Unit Test Framework introduce attributes for methods that are to be called before and after test methods. These methods are called Setup/Initialize and TearDown/Cleanup.
To comply with these standards, four attributes are offered:
Attribute Class | Applicable to | Parameters | Description |
---|---|---|---|
VirtualUserInitialize | method | This method is called before a normal test method/transaction is called. It can be used for the global initialization of variables that all test methods use. Only one method with this attribute is allowed per virtual user. | |
VirtualUserCleanup | method | This method is called after each test method is called. It can be used for global clean-up. Only one method with this attribute is allowed per virtual user. | |
TestInitialize | method | This method is called before each test method/transaction. It can be used to initialize variables that are utilized by the subsequent test method. | |
TestCleanup | method | This method is called after each test method/transaction. It can be used for clean-up after a test method call |