Unit Testing Using Visual Studio 2010
page 1 of 5
Published: 05 Apr 2011
Unedited - Community Contributed
This article will demonstrate how to use Visual Studio 2010 to develop, run, and maintain unit tests.
by Vince Varallo
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27526/ 57


One of the steps all good developers take when developing an application is unit testing.  Unit testing involves testing a single method or function to ensure it is behaving as expected.  From what I've seen through real life experience is that when a developer initially develops his or her method they thoroughly unit test it. However, when changes are made for a new release I've seen the process fall apart.  A lot of time developers make the change that was requested and only test the scenario that was requested without going back to make sure other scenarios didn't break.  I'm guilty of this myself.

Visual Studio has a great unit testing framework which can help solve this problem.  You can build  unit testing scripts, which are essentially classes that call your code that you can then execute to determine if you're code is working correctly.  When you make an enhancement or re-factor your code you can simply run the unit test scripts to determine that the code is still functioning properly. It will take you extra time to initially develop your code but it is worth the investment knowing that your code is working correctly and that you can more easily maintain your code with confidence.

This article will show you how to create an ASP.NET application and how to unit test the ASP.NET web page and a public class in a class project.  It will also demonstrate how to execute your unit tests individually or in a group. The code for this sample can be found here.

View Entire Article

User Comments

Title: 404 on link to code for this sample   
Name: Chase
Date: 2012-11-29 1:40:46 PM
I am getting a 404 when I click the link for the code for this sample. I'd love to try this!
Title: unit testing   
Name: Avinash Chowdary
Date: 2012-06-01 8:03:30 AM
good article and what about the asp.net web applications they don't have .Dll to refer in test project can you explain this scenario
Title: nice one   
Name: Abhishek goletar
Date: 2012-04-16 6:18:05 AM
nice article
Title: Positive Feedback   
Name: Hitesh
Date: 2012-04-16 6:15:45 AM
very best example to undesrstand.
I like it very much..
Thank you !!!!
Title: nice article   
Name: gourik
Date: 2011-05-03 5:02:26 AM
Title: unit testing   
Name: nitin garg
Date: 2011-04-06 9:00:54 PM
good article. expecting to dive deeper in next article by creating more complex test cases.
Title: Unit Testing   
Name: wasim
Date: 2011-04-06 2:00:12 PM
Title: Unit Testing Answer   
Name: Vince Varallo
Date: 2011-04-06 9:16:41 AM
The purpose of unit testing is to validate that the code you wrote performs as expected. In this example the CalculateDistance method has a few different expected results depending on the parameters that were passed in. As a developer you should test all of the expected results. If at a later date you make a change to the method you still need to validate that all of the expected results are being produced. This tool allows you to automate the process of testing your code so it should be easier to maintain and ensure the application is working as expected.
Title: Unit Testing   
Name: Dhairya Shukla
Date: 2011-04-06 2:10:55 AM
It's good understand for me, but If you can describe what is the purpose of unit testing in asp.net and how can use it.
One more think is that explain in basic and simple language

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-06-14 2:27:46 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search