+6  A: 

The project I'm on used TypeMock for many months. We actually just finished completely phasing it out in favor of Moq (completely free Apache 2.0 licensed mocking framework). You should definitely check out Moq if you haven't seen it. In addition to having the most intuitive syntax of any mocking tool I've seen, you get the benefits of compile time type checking. Very nice.

TypeMock has one significant benefit over Moq as I see it. Namely, it can mock anything. This includes sealed classes, non virtual methods, concrete types and pretty much anything else you can throw at it. If you're doing ASP.Net, and depending on how your code is structured, it can actually make mocking ASP.Net code behind classes a possibility. Quite neat.

However - We found that if you structure your code well, the benefits of TypeMock do not outweigh the price. Further, if you can't mock something with Moq, it probably means there's a smell there. TypeMock lets you be lazy, and I think that the code can suffer as a consequence. Moq and other mocking frameworks like it (RhinoMocks comes to mind) do make you think about your code as you're writing it, especially in terms of testability, but I would argue that's a good thing :) Further, our team ran in to several headaches trying to deploy TypeMock to our continuous integration server.

Long story short, TypeMock is a very powerful tool. As you mention, for unit testing old legacy code there aren't many better products. However, 1000 bucks gets you one TypeMock license, OR, a couple of resharper licenses, almost ten TD.Net licenses, a new continuous integration server or many other things. My own experience suggests that it's not worth it, but your mileage may vary!

Eric
Thanks a lot for the reply - awesome response. I have heard Moq was geat but never tried it. I will definitely start writing tests with it prior to making any decision. We are also just introducing TDD/unit testing to our team - so perhaps TypeMock might spoil us too much and for the devs that are new to unit testing / TDD, might even do more damage then good as they won't learn the real design principals behind TDD, as you hinted towards. I also agree - the price is just too much for a mocking framework I feared. Like I said - for that price, you can get something like telerik..
dferraro
TypeMock should really consider lowering their price point. Obviously they are a profitible company, but I just don't see how you can justify that much money for API that has many free alternatives... If it was 250 or even 400 then I'd say it's more of a no-brainer. But at 800, a smaller sized company like ours it's hard to justify... They should price it more on how big the dev team is / how much $ the company makes maybe..
dferraro
BTW, one thing I will give props to TypeMock for - is that SharePoint framework. We use SP heavily here so I could see huge benefits from this... Unfortunately we don't do heavy multi-threading applications, we'd never use Racer so we'd be paying a whole 400$ more just to mock SP objects...
dferraro
@dferraro - Both Moq and RhinoMocks use Castle.DynamicProxy under the covers. It's kind of a neat project for intercepting method calls and subbing in your own functionality, though it won't let you do anything the CLR won't normally let you do (mock sealed classes for example.) TypeMock, on the other hand, uses its own super fancy CLR profiler/interceptor (as I understand it) which is what allows it do all kinds of magic things (e.g. mock static methods). Good luck choosing what's best for you! P.s. we've also used the telerik ASP.Net Ajax components, they have their ups and downs :)
Eric
I read more into Moq and read their main beginners tutorial page. Syntax looks super clean just like TM. Although doesn't have as much functionality. I will also say though that I've spoken with some TM member who was very freidnly and helpful to me in just learning TDD and its infrastructure. This makes TypeMock shine as far as support goes as far as I'm concerned. And yes, as I understand it, they change calls at the IL level so they are almost writing their own programming language on top of .NET lol. Some hardcore shit.. tough decision. I'd like to hear more from ppl who have used both =P
dferraro
Eric, can I ask what your motivations were for changing? Was it purely cost$$?? How big is your team?
dferraro
Our team consists of 10 or so developers. We were actually already moving away from typemock when we got the call from the higher ups that we needed to relinquish our TypeMock licenses to another team. We were moving to Moq because we actually found its limitations appealing (i.e. thinking about code and the object model before you write it :)
Eric
+2  A: 

+1 Eric's answer - completely agree.

It's similar to MSTest's private accessors mechanism - there's a very strong chance you're looking at the problem wrong. If you end up having to use some technical McGyvery to test something, somebody is Doing Something Wrong.

Of course, the next thing that gets trotted out as a counterpoint is that there are cases where someone has already Done Something Wrong (Yes, I'm looking at you, SharePoint, WebForms and friends) and you really do need to do some complex in order to deal with the situation as it is right now.

Fighting battles like this can often be a huge timesink which in retrospect rarely makes you feel good. It's similar to saying "Oooh, I definitely need to get some form of testing on this, and the only thing that's going to work is UI automation because of where we are". Going down that road:

  • pulls energy away from a the real solution to the real problem - getting proper testing all the way down of different forms and granularity over time and facing the fact that there's lots of wrok to do and techniques to learn on the road to having a system you can feel comfortable about given the Legacy starting point that 97.92% of projects start from or tend towards at various stages

  • leaves you with a set of 'Coded UI tests' that you won't be happy with

One more thing - MSR has a Moles project they've been pimping lately which does the same sort of thing as TM, i.e., runtime rewriting via profiler hooks. Might be useful to people that feel they want/need to have something in their arsenal as backup if you ever do really run out of road with Moq in a real world scenario that you cant refactor your way out of and end up in a better place.

Ruben Bartelink