Boost logo

Boost Users :

Subject: Re: [Boost-users] Recommended mock framework to use with Boost?
From: Mathieu Champlon (mathieu.champlon_at_[hidden])
Date: 2012-01-19 19:55:09


On 16/01/2012 15:50, Dave Abrahams wrote:
> Hi Matthieu,
>
> I would really like to see a comparison of Turtle with HippoMocks. I am
> teaching a class next week and I need to figure out what to recommend
> people use/look at. Could you possibly post something?
>
> Thanks,
>
Hi Dave,

(Disclaimer : I'm the author of Turtle and more importantly I never used
HippoMocks for anything else than toying a bit, so anyone feel free to
correct me if I'm wrong...)

The main difference between the two libraries can be summarized as, given :

struct some_abstract_class
{
     virtual void some_method() = 0;
};

With Turtle you need to write the mock class :

struct some_mock : some_abstract_class
{
     MOCK_METHOD( some_method, 0 );
};

BOOST_AUTO_TEST_CASE( some_test )
{
     some_mock mock;
     // use mock...
}

Whereas HippoMocks is able to have you only write :

BOOST_AUTO_TEST_CASE( some_test )
{
     MockRepository mocks;
     some_abstract_class* mock = mocks.Mock< some_abstract_class >();
     // use mock more or less the same way...
}

At this point the question would be : why would you want to use Turtle ? :)

Obviously HippoMocks exploits the compilers implementation defined class
layout in order to hack the function table, but in the end who cares if
it does the job, I suppose.
And it seems to work on a fairly good number of platforms/compilers
according to the documentation.

However because it needs to target classes, they are cases for which
they have to be manually added (when there is no class : for template
meta programming and functors in particular).
Some other cases require writing stub classes also : when a class has
virtual methods and members (this is highlighted in the documentation)
or to mock private methods (because a pointer on a private member
function cannot be accessed).
In the end I believe if the code you write has many public virtual
methods, then the usefulness of HippoMocks is likely high, otherwise
maybe not so much because stub classes seem to be required anyway.

As for the state of both libraries today, I would say the HippoMocks
documentation is a bit sparse and the user/reference manual is lacking,
but the tutorial might be enough to get users started.
I believe Turtle has a slightly better integration with Boost.Test, is a
bit more customizable (error policy, constraint logging, ...) and seems
a more user friendly with compilation errors.
Also Hippomocks doesn't seem to have been updated later than Dec 2010
but it might be that it's stable enough (although the git repository
contains interesting unreleased features I haven't been able to make
work, such as mocking a free function).

I hope this helps,
Mathieu


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net