Typemock, my new best friend!

In particular, Typemock Isolator.

 Typemock fan

DISCLAIMER: I am in no way affiliated or receiving any compensation from the makers of Typemock. Simply a developer in the trenches loving this tool in his tool box. From thier website: http://www.typemock.com/index.php

  Isolate any .NET dependencies to make unit testing easyWhat does Isolator do?Typemock Isolator gives .NET developers the power to easily perform unit testing by making unit tests easy to write and automate.Isolator improves the bug-fix-time factor, and increases your code coverage.

 

I’m not really going to review it, but it is an excellent product for use in writing unit tests. Plays 100% with NUnit. This is simply a no brainer, a tool you must have as a professional developer working with .NET.

If you are familiar with unit testing, then you have run into the "Mock” object. It looks and works just like the real thing, but it’s not, it’s a fake that does your bidding so you can control the outcomes of the tests to hit the proper scenarios for verification. And for small loosely coupled objects, this works with the added overhead of making the mock objects. But invariably you will end up with a data-bound object or a class sub-classed 3 levels deep and controlling the testing inputs gets harder and harder to control.

There are many development patterns out there that help to mitigate this “cost” such as factories with delegated constructors to allow snapping in of the data-provider, but these quickly become very complex beasts, and the codebase is just as large as the production code. Yes it works, yes it’s thorough, but is there a better way?

Yes! Why just today, I was creating some tests around a subsystem that essentially picks what will be shown to the user based on various rules. We are re-using the subsystem with another application and since the codebase is well set up and shared between like applications, with proper testing in place, we will be able to re-factor the code to be used in both spots with much higher confidence.

For one scenario, a random number between 0 and 99 is picked values less then 50 see A and the values greater then 50 see B. Well to right a test for this, you really need a consistent value returned from the random number generator. In my case, the random number was being returned from a private static little wrapper function around Random.GetNext() which I wil call GettRandomInt for namesake.

Typemock Isolater allowed me to intercept the call to GettRandomInt and force a return value of whatever I need for that test to be able to fully test my scenario. In a single line of code. That’s right 1 DAMN LINE OF CODE, I almost cried. Mind you I got lucky in that it was a static function so I never needed an instance, but at worse, 2 lines of code. Not too bad. And it was a private member as well. It has always been a source of frustration to only be able to test public functions, or to break ideal object model integrity for testing purposes alone. I mean of course quality is the clear choice here, but it isn’t free.

I was just very impressed with the product through a single day’s use. If you have ever “mocked autoquote” (and you know who you are (-: ) I guarantee, that’s right I said it, GUARANTEE, your satisfaction! I will be buying the personal edition for myself to use on my own projects, and for $89.00 that’s quite affordable.

They also have SharePoint isolator which I have not used, but have worked with SharePoint. And I can only imagine how this would be an essential tool.

Anyway, thank you Rob Witt for showing me the light. Amazing!

Regards!

4 Responses to “Typemock, my new best friend!”

  1. Gil Zilberfeld says:

    Hi Monkk,

    Wow, you just made my day!

    I’m glad you like our product. We take great pride in that you can do all this stuff, and with a few lines of code.

    How long have you been doing unit-testing?

    Thanks again for the kind words,

    Gil Zilberfeld
    Typemock

  2. Monkk says:

    I’ve been formally unit testing for about 6 years now. Thanks for the great product! My only question is why can’t one mock things in the mscorlib? Not really a big deal, but I did recently have a case where a function under test makes a call to Random.GetNext() and I needed to control it’s return value. It wasn’t really a big deal, I just wrapped the call to it in another function and was able to control it’s return value. But I could see cases where maybe working with streams or readers where more control would be nice without having to subclass and wrap ‘em. But really, that’s not a deal breaker at all!

  3. Gil Zilberfeld says:

    Hi Monkk,

    The MSCorLib stuff is something we’re battling for a long time. If you fake DateTime.Now (our favorite request) you may get what you ask for, but not what you expected. That’s because, mscorlib uses these types as well. That’s why the wrappers are needed, to make sure that you fake the correct thing. By the way you CAN fake interfaces defined in mscorlib.

    If you’d like, drop me an email, I’ll enter you into our insider list, so you’ll know what’s happening before everyone else.

    Thanks,
    Gil

Leave a Reply