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.