The pains of unit testing the front-end portion of ASP.NET far outweigh the benefits. It's easier and more worthwhile to stick with your domain and data layers.
Lately, I've been working on a project that makes heavy use of HttpHandlers. A significant amount of code has nothing to do with classes in the System.Web.UI namespace - so no controls, no viewstate, no postback. Since those are all the things that make unit testing ASP.NET a nasty affair, I figured it might be worthwhile to try and unit test the code in question.
It ended up being really easy, and although I've built a mini-base test class for my test fixtures to inherit, it really all comes down to 1 very simple method:
protected string RawRequest(string fileName, string queryString)
{
StringBuilder output = new StringBuilder();
using (StringWriter sw = new StringWriter(output))
{
HttpResponse response = new HttpResponse(sw);
HttpRequest request = new HttpRequest(fileName, "http://fueltest.net/" + fileName, queryString);
HttpContext context = new HttpContext(request, response);
new RequestHandler().ProcessRequest(context);
}
return output.ToString();
}
where RequestHandler() is my core HttpHandler.
My tests are able to validate that the output, given the querystring inputs, are correct.