views:

75

answers:

2

I've been reading about MVC in which the authors suggest that testability is one of the major strengths of MVC. They go to compare it with ASP.NET WebForms and how difficult it is to test the code behind in WebForms.

I do understand it's difficult but can someone explain how unit tests were written to test code behind logic in the old days?

+1  A: 

The code behind are plain methods in a class (the only difference with another class is that this class inherits from the Page object)

So it is testable. most problems arise because the methods were tightly coupled to web.ui controls like the grid; they were not so easy to fake. If you didn't fake the UI controls, you were also testing the inner workings of the UI controls which is a little overdone.

Michel
+1  A: 

In the old days I tested aspnet webforms using the pattern Model View Presenter. I was able to test code with this pattern because I abstracted the conditional logic / loops / etc into a separate class that didn't live inside the webforms framework.

What was left in the webforms codebehind was nothing more than a few properties and a call in the page load to init the presenter class itself.

Then each event handler would simply pass off the work to the presenter class.

I've spent a great deal of time with this pattern and found that it makes things much more test friendly but it's a great deal of work compared to aspnet mvc

Toran Billups