Sunday, December 7, 2008

Visual Studio Test Attributes

When we built our test in the previous section, we were required to use the following two attributes:
· [TestMethod] – Used to mark a method as a test method. Only methods marked with this attribute will run when you run your tests.
· [TestClass] – Used to mark a class as a test class. Only classes marked with this attribute will run when you run your tests.
When building tests, you always use the [TestMethod] and [TestClass] attributes. However, there are several other useful, but optional, test attributes. For example, you can use the following attribute pairs to setup and tear down tests:
· [AssemblyInitialize] and [AssemblyCleanup] – Used to mark methods that execute before and after all of the tests in an assembly are executed
· [ClassInitialize] and [ClassCleanup] – Used to mark methods that execute before and after all of the tests in a class are executed
· [TestInitialize] and [TestCleanup] – Used to mark methods that execute before and after each test method is executed
For example, you might want to create a fake HttpContext that you can use with all of your test methods. You can setup the fake HttpContext in a method marked with the [ClassInitialize] attribute and dispose of the fake HttpContext in a method marked with the [ClassCleanup] attribute.
There are several attributes that you can use to provide additional information about test methods. These attributes are useful when you are working with hundreds of unit tests and you need to manage the tests by sorting and filtering the tests:
· [Owner] – Enables you to specify the author of a test method
· [Description] – Enables you to provide a description of a test method
· [Priority] – Enables you to specify an integer priority for a test
· [TestProperty] – Enables you to specify an arbitrary test property
You can use these attributes when sorting and filtering tests in either the Test View window or the Test List Editor.
Finally, there is an attribute that you can use to cause a particular test method to be ignored when running a test. This attribute is useful when one of your tests has a problem and you just don’t want to deal with the problem at the moment:
· [Ignore] – Enables you to temporarily disable a test. You can use this attribute on either a test method or an entire test class

1 comment:

MS CRM 2011 KB Article customization Issue.

Recently I have encountered some issue while customizing Kb Article Entity. I was doing following configuration in Article form. 1. Add Ba...