Monday, September 03, 2007

Unit testing my web application

As I have recently started a new web application (actually it is going to grow in to our Intranet) I have decided to develop it along an agile path using unit tests. It has been a bit of a struggle at first, but I now have a basic framework. Writing the actual tests was never a problem as I have used NUnit before on a couple of windows based projects, this was however the first time with a web application. The easiest way I have found is by creating a web application instead of a web site in VS2005. By creating a web application, dll's are created at build time which NUnit will run against. Now that is up and running I wanted to use mock objects to basically mock session variables. I highly recommend Rhino Mocks as a mocking framework. You cannot however mock the session as it is sealed. After Googling for a while I came across this post by Phil Haack which uses an HttpSimulator. I thought I was almost there, but there was a problem with a map path interface having restricted access due to its protection level. Reading the comments lower on this page is a simple solution to comment out any reference to ConfigMapPath. So finally I can now unit test my session variables. Sorry for the long story, but it may help someone (myself included when I totally forget about it on my next web application project).

On a side note I finally took the plunge and am now using Windows Live Writer to update this blog. It is still in beta, but if you want to give it a try, go to the URL here.