Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding unit testing to an existing asp.net web forms application

I have an existing asp.net webforms application that I would like to add some unit testing to but am unsure of exactly how to go about it.

The application is database driven with functionality I guess you could compare to an advanced forum. Logic, data access and presentation are seperated for the most part.

What methods should I be testing?

How do I handle the database and test data?

Are there any tools recommended to assist in this?

like image 540
Luke Lowrey Avatar asked Jun 26 '09 00:06

Luke Lowrey


People also ask

What can be used for unit testing in .NET solutions?

xUnit is a free, open-source, community-focused unit testing tool for . NET. The original inventor of NUnit v2 wrote xUnit.net. xUnit.net is the latest technology for unit testing .


2 Answers

The first thing you need to decide is: What is your motivation for adding unit tests?

There are many excellent reasons for having unit tests (I rigorously practice TDD myself), but knowing which one is the main driving force in your case should help you decide which tests to first write.

In most cases you should concentrate on writing unit tests for the areas of your application that have been causing you the most pain in the past.

Much experience has shown that when software originally was written without unit tests, it can be hard to subsequently retrofit unit tests. Working Effectively with Legacy Code provides valuable guidance on how to make an untested software projects testable.

like image 131
Mark Seemann Avatar answered Sep 25 '22 01:09

Mark Seemann


I would most likely test the backing methods that your web forms call (bypassing the forms validation), this will let you test the logic and data access.

As for the test data, a seperate test database would be the best option. Otherwise i suggest having the test methods remove the test data once its completed.

like image 33
dkarzon Avatar answered Sep 23 '22 01:09

dkarzon