views:

49

answers:

2

Ive been learning MVC2 and MVVM lately and I think it works like this.

ASP.NET MVC2 - Can test the whole web site using unit tests

ASP.NET MVC2 + jquery web service calls - Can no longer just use MSTest unit test. What is the MS product to test the javascript side?

ASP.NET Webforms - Unit Tests are near impossible when the coder doesnt create the Webforms site with Testing in mind. Therefore Asp.NET web performance tests are the closest thing to testing that is realistic. Coded UI Tests are too trivial to really be useful for things like ASP.NET validators.

ASP.NET Webforms + jquery web service calls - Can only unit test the web service calls. Cannot use Web Performance tests because of javsscript calls. Need some sort of javascript testing framework.

Silverlight - No tests. Maybe Coded UI Tests.

Silverlight MVVM - Use silverlight unit test framework to test ViewModel similiar to MVC.

Silverlight MEF - How does MEF affect testing scenerios if at all ?

Is this accurate? Is there anything I am missing ?

I am trying to make a argument to the people in charge that we should use MVC over Webforms so that we can create automated testing. As it is we are doing Webforms all in one project and impossible to test so people just test off of manual scripts :(

+1  A: 

Rather than specifying the reasons why you should use MVC over Webforms, I'd take a step back and sell the management team on why you should use unit tests. After that's sold you have a case of saying that MVC would allow you to do this more efficiently than webforms.

Are you looking at going the full TDD route, or just creating tests after? I'd highly recommend going down the TDD path even though it does have a steeper learning curve and will lessen your productivity while you are learning it.

Since you are already looking into testing, you probably know most of these, but I'll re-iterate some of the benefits:

Less defects get through to QA.

Tests can be created for issues that QA and customers find.

Designing for testing creates a more loosely coupled application which tend to be more maintainable.

Increased developer confidence when making changes leading to sustained productivity as the application code base matures.

Tests are great documentation for new developers joining the project, as they can see what's trying to be achieved.

Note: the cost of fixing a defect that has made it through to production can be up to 80 x the cost of finding and fixing it in the development and QA process (I'll try to find my source for that figure).

Unit testing is only one piece of the puzzle though, you'll also want to look at using a Continuous Integration server such as CruiseControl.NET to automate your builds and tests. This will make sure that everyone keeps the build in a working state.

For an existing Webforms project you might also want to look into the Web Client Software Factory. I've found it to be very useful for migrating legacy webforms apps over time, though it's a little more convoluted than MVC2.

James O'Sullivan
In reference to the cost of fixing a bug in production, try searching for the 1:10:100 rule.
James O'Sullivan
Good point to sell the concept of unit tests first.. They are not that technical and I think stressing how much fixing bugs is costing us is a good idea.. But I also need to sell it to the devs and the main problem is they never have done any TDD or thought of unit testing.. so my stradegy is try to get a small project to do myself that I can then use as a template for why unit testing is helpful.I think CI is too much too ask.. we are still Xcopying files (except the web.config) to the different serversId prefer to start from stratch with MVC2 rather than salvage our webforms stuf
punkouter
Getting developers on board with TDD can be challenging but isn't insurmountable. Your small project idea is a good one and can provide some code for training materials. I'd also recommend trying to find another forward thinking developer as an ally so you can have a top down and a grass roots effort. If a dev can understand how it can make their life easier they'll generally go for it.
James O'Sullivan
Depending on the size of your current code-base I wouldn't recommend starting a complete rewrite. These are generally very costly as you have two code bases being worked on at the same time. You're better off trying to merge MVC into your current project and as you work on the older code, refactor it into the new style. I've done this a number of times with much success with WCSF. I haven't tried updating a legacy app with MVC yet but it should be able to coexist in the same project.
James O'Sullivan
Im already spreading my MVC propoganda to the old school 'Just get it working in webforms however you want' people.. If I can't use MVC my plan is to create a MVC client in parallel to the OFFICIAL client and hopefully in the end I can prove we should be using testable frameowrks.its a gov job.. so natturally alot of people tend to want to do whatever requires the least effort.. and learning a new frameowkr requires them to do some work so thats a problem.
punkouter
A: 

I don't know about other technologies, but I can talk about using Silverlight with MVVM pattern. Using MVVM pattern along with command pattern, we have been able to unit test all of our C# code. I mean barring xaml code, we have a very high code coverage for our C# code. We actually use a modified version of MVVM wherein we also use a controller. If you ensure that you have no code in code-behind files, you can simulate button click/other such UI events. This is very useful for integration tests. We have found out that our pattern of MVVM along with controller and using command pattern facilitates unit testing.

P.K
I was playing with MVVM all week.. I like it but Blend needs to be updated to work with people who are doing MVVM..
punkouter
Agreed. I use blend only for something which I find it difficult to do in Visual Studio, say visual states. I currently used Blend 3. Haven't tried Blend 4 to see if anything has improved.
P.K