SIGN UP MEMBER LOGIN:    
ARTICLE

Unit Testing with VS 2008 Team edition

Posted by Kalyan Bandarupalli Articles | Learn .NET February 15, 2009
Unit tests allows the developers and testers to check the logical errors in the methods of classes in C# and VB.NET Projects.Unit test can be created once and can be run every time that source code changes.Unit test cases make sure that no bugs are introduced when you write the new code.
Reader Level:

Introduction

Unit tests allow the developers and testers to check the logical errors in the methods of classes in C# and VB.NET Projects. Unit test can be created once and can be run every time that source code changes. Unit test cases make sure that no bugs are introduced when you write the new code.

The more about TDD using C# and concepts here. This post speaks about Unit Test Framework that introduced in VS 2008 Team Suite for developers that was not available in VS 2005 and also explains about creating and running Unit Tests.

1. Create a new Class library project in VS 2008 and write the following code in class


 
2. Right click on the WithDraw() method in the above class then select Create Unit Tests option.

3. You will get the Unit Test dialogue box as shown below

A new test project will be created in the solution and notice that every method is assigned the TestMethod()  attribute. The class which contains these test methods are assigned TestClass() attribute.

4. The next step is to set the values to the variables in the test method

5. Save the values in the file and open the Test List editor from the solution it looks like as follows

6. Check the Test cases that you want to test from the above editor and click on run button you will see the results of the test cases as follows


 
Conclusion

We have learned creating a test case and running using the Unit Test case framework in the Visual Studio 2008 Team edition. In the next article I will discuss about more test attributes and features provided by the Unit Test Framework.

Login to add your contents and source code to this article
share this article :
post comment
 

Hi Can you help me in understanding,how this test would help me in testing multiple values, Currently I can see that "Scott" "Philip" 37 values are hardcoded. Ideally tester would test the scenario for multiple values..

Posted by Sachin Thorat Jan 29, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor