Alex Rivera | Logout

How unit testing is better in ASP.NET MVC than Web Forms?

Asked 2010-07-15T19:54:56.507
14

I have just started to learn ASP.NET MVC. When comparing ASP.NET MVC with Web Forms one of the main advantage of MVC is always told to be better support of Unit Testing. Can I got a good explanation of how it has better support?

Edit : If possible please provide example in both.

Edit
Report

2 Answers

3

If you want to use ASP.Net WebForms (like i do) and unit tests together, take a look at this:

WebForms MVP on codeplex

Works for me.

answered 2010-07-18T14:16:28.490
2

You can do exactly the same thing with Web Forms, it's just that people who don't know better write code that can't be tested this way.

There's no reason to have business logic in a codebehind class. Same with data access logic. Even right there, that lets you test the parts of the application most subject to both bugs and testing.

Some might say that doesn't allow you to test for button clicks and other user-interface events. If you want to do that, then you can go ahead and create your own MVC or MVP or other such pattern, that does use a separate interface for the user interface actions. Then do exactly the same kind of test you'd do if using ASP.NET MVC.

And you still have the problem of not being able to test client-side code.

answered 2010-07-15T20:02:27.290

Your Answer