Before the flame war starts up I want to say I believe in test driven development BUT you really don't need unit testing for every single class that you create. I'm sorry but the AboutUs controller method seriously does not need a unit test. Those of you who are in shops where unit testing is forced on you then you realize how time consuming it can be to create good unit tests. Especially if your lazy and wait till the end of the week to make them. So for those of you who want to make reasonably stable applications and not have to create all this unit testing classes then you can try this:
public class ErrorLoggingAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.Exception != null)
{
CustomErrorHandlingClass.ReportError(filterContext.Exception);
}
}
}
So you'd place this code in one of your controllers and this would create a method attribute that you can use throughout your MVC Application. What that would like like is something like this:
[ErrorLogging]
public ActionResult Index()
{
return View();
}
Its that easy, and when an error happens your CustomErrorHandling Class can notify you in some way that there is a problem such as an email. I can't tell you how many times this has found deep errors in my system (stuff the unit testing would of never found). Now I am not saying get rid of unit testing, but you may just want to reserve it for mission critical stuff like making sure your ShoppingCart class is adding properly :D.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5