Today I attended a workshop on Visual Studio Team System 2008 at Microsoft’s official headquarter in my hometown Recife, Brazil. One of the key aspects as a developer that I believe I don’t do a lot of is testing the application.
One of the features that Igor Abade showed us was the Test Unit. It immediately became clear to me how this could be applied in my work environment and how it could eventually become a common practice in my company. Important features could have test units associated and prevent a meltdown when another feature is added or modified.
Check out the step-by-step guide after the break!
Now the first thing to realize about this feature, is that it’s not available with all versions of visual studio. In fact, it is only available for the Team System version which is the more complete. There are several debates and even a petition about whether or not Microsoft should include unit testing in all versions of visual studio. I will let you follow the links and make up your own mind.
In order to further understand the use of unit testing, I will – as I did in my other howto blog post- describe a brief problem and follow with a howto of how I solved the problem using unit testing.
Problem:
The following code illustrates a simple Account class in C# that follow these simple rules to calculate the account’s credit:
- If the balance of the account is smaller than or equal to $2,000 , the owner of the account will receive an immediate approval of 10% of it’s balance.
- If the balance is greater than $2,000 , the account’s owner will receive 20% if the balance.
- Additionally, if the owner has a premium account, he’ll receive $1,000 of extra credit.

Scroll down to the end of the Test file that automatically is set on your VS. Here you'll see a few lines of code marked with TODO. These are the lines of code you'll modify to create the test.

Modify the value of the parameters with the desired input, and set the desired output in the expected variable.
Tags: HOWTO, test units, vs2008






October 22, 2008 at 9:21 am |
Good introduction Nelson. One thing about that petition you link to is that at the time it was posted, Unit Testing features were only available in VSTS Test Edition and Suite. What the petition was calling for has happened and now Unit Testing is available all the way down to the Pro version of Visual Studio.