Search code examples
c++unit-testingmockinggooglemocktypemock

Which mocking frameworks allow zero changes to legacy code?


I am searching for a mocking framework for a large C++ project. I've tentatively chosen GoogleTest as the testing framework so I first looked at GoogleMocks. However, I then discovered TypeMock's Isolator++ which has two features I very much liked:

  1. It can mock anything.
  2. It allows you to add test coverage without changing legacy code (using method call interception & maybe some other magic). No need to splice in interfaces to add tests.

The drawback is that Isolator++ is a commercial product. I worry about vendor lock-in & such. Are there other frameworks which have the same capabilities? Perhaps something open source?


Let me also preclude a common criticism I've observed in other posts: "TypeMock encourages bad design. You should improve your design rather than use a tool which supports bad habits." (my paraphrase)

My response is this: I do want to improve design. I also want to add test coverage BEFORE refactoring. To that end, the ability to add tests with zero code changes is very attractive.


Solution

  • Well, I suppose this post could also be titled: "Does TypeMock Isolator++ have any competitors"? As far as I can tell, the answer is no.

    For C# code, TypeMock Isolator does have a couple competitors: Telerik JustMock & Microsoft Fakes. However for C++, TypeMock Isolator++ is the only one I've found.

    For anyone in this situation, I also suggest a reading of Michael Feather's book "Working Effectively with Legacy Code". It offers many practical tips for getting tests in place without needing to mock live objects as Isolator lets you do. That said, there are cases where the necessary changes are simply too invasive in my opinion. They introduce too much risk while getting tests in place. So, perhaps Isolator++ might be worth the money. We'll see...