views:

862

answers:

5

I'm getting into more of a TDD workflow, and have a mix of MVC and asp.net Web Forms apps.

MOQ is recommended for MVC.

I've used Rhino for Web Forms.

Does anyone have a best practice for having 1 framework mock for both?

A: 

I would just go ahead and use my favourite framework for both. I don't think there's any reason that I would choose one framework for web forms and another for MVC. A far bigger problem is how I would unit test my web forms pages at all, since it's notoriously hard to seperate the page from the rest of the HttpRequest stack.

My favourite is Moq. I've also used TypeMock. It costs money, but it's really powerful - it lets you mock concrete classes and constructors, so you could potentially mock things like HttpContext or HttpRequest.

Rory MacLeod
A: 

Rhino's latest release includes much of the sweet sweet 3.5 love that MoQ has. I'm a fan of MoQ, so that's what I'm using. But I also have Rhino, in case it does something that MoQ doesn't do.

TL;DR: MoQ it baby.

Will
A: 

TypeMock is insanely powerful. When I needed to unit test a web forms app that wasn't designed for testability TypeMock saved my life.

But when I take the time to pick an architectural pattern (MVC) or design one that allows for Mockability (you know, public virtualize state changing methods) I use Moq. It is so simple to use and so simple to teach others.

TypeMock's record replay syntax still confuses me, but it saved me plenty of time in a tight release schedule. Moq's API is almost self explanatory which is an amazing achievement given the mock library history.

CVertex
A: 

This is sort of a silly question, but I prefer Rhino Mocks as it represents a more complete understanding of mocks vs. stubs.

Look deep into TypeMock before committing to the price.

Also, there is no recommended mocking framework for ASP.NET MVC.

Finally - I'd suggest you stick to one mocking framework in your project (and even in your team) - the differences, while not huge, can lead to confusion that is unwarranted on such a "polishing-the-rock" decision. By that I mean the decision should not be a long one, just pick what works and get on with creating value.

Matt Hinze
A: 

Look into Ivonna for faking HTTPContext and traditional webforms.

http://sm-art.biz/Ivonna.aspx

Roy

RoyOsherove