Wednesday, May 28, 2008

A positive look at unit testing

Often we find ourselves under stress trying to deliver a module on time. Some of the first reflexes that come to mind, are to eliminate going through some layers, or simplifying (especially the asp.net layer), and many other reflexes (including myself).

Testing Data Access, Services and Security Layers can be easy, since it really does not require a special context to run on. As for asp.net UI and presentation layer, it's been quite difficult, until the ASP.NET MVC framework preview comes in, with the support for testing the UI layer.

Unit Test layer as a conception layer:
In fact, when we start unit testing, we need to know that testing is at the beginning, during and at the end of development phases. Besides, the unit tests framework is by definition a framework, now, how we use it is totally up to us.
To create a concept for our development of a data access layer, we can use our unit testing framework to

create methods that show us :
                                        1. how we will use the data access layer (opens a conception discussion)
                                        2. It provides us a framework for testing thoroughly our data access layer
                                        3. It also provides us with a controlled manner of building up the solution

Unit Test layer as a documentation layer:
Finally, one of the great benefits (by experience) we went through, is the fact that the unit tests layer can serve as a documentation layer (perfect fit).
In one of the project we worked on, we used the Unit tests layer to train any new team members, to get up and running quickly with using the layer He/she is concerned with. It was a great way to document using code and comments, we could also create a CHM file for it, and also, since it's a collection of unit tests, it works.

A unit tests layer, a CHM documentation file, and making sure tests work, can really be a great way to have a major part of the documentation to train new team members

In conclusion:
As much as the unit tests layer can cost in terms of resources and time, It builds up a great layer for the long term use of applications. Unit tests should be used for many layers, if not, then at least for one or two layers in the application, in order to minimize maintenance cost later on.
Good team work is necessary to the success of good unit tests layer.

Useful links :

ASP.NET MVC , ASP.NET MVC Quick Starts,

Comments are more than welcome