Roy Osherove

View Original

TypeMock 3.5 is out - and it's powerful!

The wizards at TypeMock.com have released a brand new version of TypeMock - one of the coolest Mocking frameorks you've never heard of - and it's a shame you hadn't.
(if you're new to this product, look at the bottom of this post for an explanation)
 
Here are some of the updated features in the new version:
 

 

Natural TypeMocks™
(Professional and Enterprise Editions)

TypeMock.NET now supports the innovative Natural TypeMocks™ way of defining expectations.
Using Natural TypeMocks™ Refactoring and compiler strong typing can be used with mocked objects

using (RecordExpectations recorder = RecorderManager.StartRecording())
{
   // CAUTION: ALL calls here are mocked!!!
   Logger.Log(Logger.NORMAL,null); // This is mocked
}

 

Chained Natural TypeMocks™
( Enterprise Editions)

With Chained Natural TypeMocks™, you can now set expectations to a full sequence of calls

using (RecordExpectations recorder = RecorderManager.StartRecording())
{
   Dogs.GetDog("rusty").Tail.Wag().Speed(5); // All calls are mocked
}

 

Better Static Constructor Story

TypeMock.NET now handles mocking static constructors in a much better way.
Now the static constructor will be called if it was mocked in a previous test and is not the current one

Auto-Deploy for Build Servers
( Enterprise Editions)

It is now possible to run TypeMock.NET tests without installing the software

64 bit Side by Side

64 bit and 32 bit TypeMock.NET versions can now work together on the same machine.

Many other cool things

  • Ability to Mock ANY Concrete Class and ALL members:
    Public, Protected, Private, Virtual, Non-virtual, Constructors and Sealed.
  • Mocking takes place on the fly, working on your production assemblies.
  • Easy expectation recording, giving you full control on mocking.
  • Built in argument checks.
  • Support ref and out arguments.
  • Allow arbitrary calls, or reject any method calls that weren't explicitly expected.
  • Enables you to specify sequenced and default return values and exceptions.
  • Support for properties and indexes.
  • Verify mode, to verify arguments without mocking the code.
  • Ability to specify dynamic return values based on passed arguments.
  • Enables you to validate the arguments passed to the mocked types.
  • Specify custom checking of arguments.
 
What's TypeMock?
Basically it allows mocking out (replacing) any object, method or member in your code at runtime. even static method calls, singletons and direct calls to objects can be replaced with "fake" ones, in a few lines of code. That helps write test for code that has a lot of dependencies on other code classes (even web services) without having to change the code to test it.
 
Sounds too goo to be true?
They are doing it using CLR Profilers (an advanced technique that lets you "intercept" any call to any object - even system classes if you want). It's true, but it does have one big shortcoming for me (outlined in red below)
 
The benefits touted on the website are:
  • Enables testing code that was previously 'untestable'.
  • Reduces time spent on writing unit tests, giving you more time to focus on your real tasks.
  • Cuts development time and increases your efficiency by having repeatable unit test.
  • Saves time by eliminating refactoring and restructuring of your code, just to make it testable.
  • All this is for FREE.
  •  
    I outlined that line in red to make a point: Part of the beauty of writing unit tests is that it forces you to restructure and refactor your code for testability. In fact, Testability can indicate a good design. Which is qhy I don't use this tool in my classes about Test Driven Development.
    However, I do see lots of use for this in places where refactoring is impossible, or you need to write integration tests that are very complicated. It can help QA people as well as developers, and I do think it's a very good tool to have in your tool belt.
    You just need to know that it hides the idea of good design from you, and lets you plow through your tests as if all is well. That's both good and bad. As long as you know the difference - you're OK.