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

Monday, December 1, 2008

Unit test in VS 2005

If you didn't know it already, it is not a difficult one to learn.Tremendous progress is being made on several fronts: IDE integration, process integration, and new test fixtures. In here I will cover unit testing in Visual Studio 2005, including VSTS unit testing, NUnit and MBUnit--the Superman of unit testing. First post I’ll cover NUnit testing.

NUnit
NUnit is the unit testing framework that has the majority of the market share. It utilizes attributes to identify what a test is.
The TestFixture attribute is used to identify a class that will expose test methods.
The Test attribute is used to identify a method that will exercise a test subject.
Let's get down to business and look at some code. First we need something to test.
public class Subject
{
public Int32 Add(Int32 x, Int32 y)
{
return x + y;
}
}
That Subject class has one method: Add.
We will test the Subject class by exercising the Add method with different arguments.
[TestFixture]
public class tSubject
{
[Test]
public void tAdd()
{
Int32 Sum;
Subject Subject = new Subject();
Sum = Subject.Add(1,2);
Assert.AreEqual(3, Sum);
}
}
The class tSubject is decorated with the attribute TestFixture, and the method tAdd is decorated with the attribute Test.
You can compile this and run it in the NUnit GUI application. It will produce a successful test run.
That is the basics of what NUnit offers. There are attributes to help with setting up and tearing down your test environment:
SetUp, SetUpFixture, TearDown, and TearDownFixture. SetUpFixture is run once at the beginning when the fixture is first created; similarly,
TearDownFixture is run once after all tests have completed. SetUp and TearDown are run before and after each test.
NUnit tests can be run several different ways: from the GUI application, from the console's application, and from a NAnt task. NUnit has been integrated into Cruise Control .NET as well. In the last product review, you will see how it has been integrated into the VS.NET IDE as well.

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...