Testing Asp.Net Applications easily with TypeMock

Unit Testing an ASP.NET web application has been quite troublesome. This is one of the reason to why alot of teams adopting the Model View Presenter pattern. I've posted in the past on how to approach unit testing on the pattern.

Typemock has an interesting proposition for the ASP.NET developers; the ASP.NET Bundle. I am interested to see how this product pans out and will be hopefully doing a full review on the product in the near future.

The general idea seem to be an attribute driven approach [RunOnWeb] which then allow the developers to have access to the web specific global variables (HttpContext, Page, etc) easily.

[TestFixture, RunOnWeb]
public class MethodTester 
  	public void WhenShowMessageIsInvoked_MessageLabelShowsTheMessage() 
   	     //start a browsing session
   	     var session = new TestSession();

   	     //request a page
   	     var page = session.GetPage("Default.aspx"); 

   	     //invoke the method
   	     (page as IView).ShowMessage("message"); 

   	     //find  label
   	     Label messageLabel = page
                   .FindControl("MessageLabel") as Label;

   	     //check  text
   	     Assert.AreEqual("message", messageLabel.Text, "Invalid text");

The examples above shows you that we can get an instance of the page even up the controls. It's pretty powerful stuff. One of the biggest drawback with adopting MVP pattern is the fact that I still can't test the view effectively. If you look at the ASP.net MVC without the framework: Unit Testing, you will notice that I didn't test the view. It looks to me that TypeMock will easily fill in that role.

The ASP.NET Bundle coonsists of a couple products: Typemock Isolator, a unit test tool and Ivonna, the Isolator add-on for ASP.NET unit testing. Typemock Isolator is targeted towards testing SharePoint, ASP.NET, MVC, WCF, WPF, Silverlight and more. Note that for unit testing Silverlight there is an open source Isolator add-on called SilverUnit.

Interested in trying? click the following link for more information on how to get your free license. Hopefully I'd get one so I can tell you my opinions about the bundle.