Recommended mock framework to use with Boost?

Hi -- I'm trying to learn to develop properly with C++ and Boost, and to that end am learning along with Boost.Test, as I'm a BDD coder in another language (Ruby) in my day job. I'm at the point, now, where my tests could really benefit from a mocking framework. There doesn't appear to be one in Boost (not documented, at least), so I wondered if anyone on the list could recommend a mocking framework that they use that works well with Boost.Test? Any and all advice gratefully received, Doug.

On 05/01/2011 20:09, doug livesey wrote:
Hi -- I'm trying to learn to develop properly with C++ and Boost, and to that end am learning along with Boost.Test, as I'm a BDD coder in another language (Ruby) in my day job. I'm at the point, now, where my tests could really benefit from a mocking framework. There doesn't appear to be one in Boost (not documented, at least), so I wondered if anyone on the list could recommend a mocking framework that they use that works well with Boost.Test? Any and all advice gratefully received,
Hi, I wrote and use quite extensively http://turtle.sourceforge.net It still requires some work (and probably 2 or 3 total rewrites in the process :p) but it meets my needs and overall works better than the library I was using previously http://mockpp.sourceforge.net Cheers, MAT.

I'll have a read of that, thankyou very much!
On 7 January 2011 14:44, Mathieu Champlon
On 05/01/2011 20:09, doug livesey wrote:
Hi -- I'm trying to learn to develop properly with C++ and Boost, and to that end am learning along with Boost.Test, as I'm a BDD coder in another language (Ruby) in my day job. I'm at the point, now, where my tests could really benefit from a mocking framework. There doesn't appear to be one in Boost (not documented, at least), so I wondered if anyone on the list could recommend a mocking framework that they use that works well with Boost.Test? Any and all advice gratefully received,
Hi,
I wrote and use quite extensively http://turtle.sourceforge.net It still requires some work (and probably 2 or 3 total rewrites in the process :p) but it meets my needs and overall works better than the library I was using previously http://mockpp.sourceforge.net
Cheers, MAT.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

At Fri, 07 Jan 2011 14:44:18 +0000, Mathieu Champlon wrote:
I wrote and use quite extensively http://turtle.sourceforge.net It still requires some work (and probably 2 or 3 total rewrites in the process :p) but it meets my needs and overall works better than the library I was using previously http://mockpp.sourceforge.net
<applause> That looks like a pretty nice facility. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On 07/01/11 18:35, Dave Abrahams wrote:
At Fri, 07 Jan 2011 14:44:18 +0000, Mathieu Champlon wrote:
I wrote and use quite extensively http://turtle.sourceforge.net It still requires some work (and probably 2 or 3 total rewrites in the process :p) but it meets my needs and overall works better than the library I was using previously http://mockpp.sourceforge.net <applause>
That looks like a pretty nice facility.
I was about to say: anyway to get this turned into Boost.Mock ? The library looks really well done.

On 07/01/2011 19:19, Joel Falcou wrote:
anyway to get this turned into Boost.Mock ?
On 07/01/2011 19:19, Kenny Riddile wrote:
Is this something you're eventually planning to submit for review?
Yes that's something I've been thinking about. I still need to sort out a couple of things regarding the public interface, then I plan on boostifying it and start gathering some feedback. Thanks for the motivation boost ! MAT.

I've been really slow to get to this, because I'm still learning all of this
C++ Boosty goodness (and I'm pretty slow, anyways), but ... Wow!
That looks amazing -- you've written something there that even *I* can make
sense of!
Thankyou very much!
On 8 January 2011 18:24, Mathieu Champlon
On 07/01/2011 19:19, Joel Falcou wrote:
anyway to get this turned into Boost.Mock ?
On 07/01/2011 19:19, Kenny Riddile wrote:
Is this something you're eventually planning to submit for review?
Yes that's something I've been thinking about. I still need to sort out a couple of things regarding the public interface, then I plan on boostifying it and start gathering some feedback.
Thanks for the motivation boost !
MAT.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

on Sat Jan 08 2011, Mathieu Champlon
On 07/01/2011 19:19, Joel Falcou wrote:
anyway to get this turned into Boost.Mock ?
On 07/01/2011 19:19, Kenny Riddile wrote:
Is this something you're eventually planning to submit for review?
Yes that's something I've been thinking about. I still need to sort out a couple of things regarding the public interface, then I plan on boostifying it and start gathering some feedback.
Thanks for the motivation boost !
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, -- Dave Abrahams BoostPro Computing http://www.boostpro.com

Dave,
On Mon, Jan 16, 2012 at 9:50 AM, Dave Abrahams
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?
If you got a private response on this that you can share, I would personally like to see it. I started down the road of using Turtle about a month or so ago before I had to redirect current time to something different. I liked it, but I admittedly didn't get very far. What I found in my situation, though, was that mocking took a substantial amount of development effort in a "legacy"(*) body of code such that creating tests that rely upon mocking was more trouble than it was worth at first evaluation, i.e., it did not save me more time than it cost. As this was my first experience with an actual mocking framework (as opposed to ad-hoc bespoke stuff created for a single purpose), I'm not sure if it's a framework issue, a user (me) issue, an impedance mismatch between the framework and legacy code, or what. I suspect that the reality is that it's a little of all of them. If anybody knows a mocking framework that slides easily into existing, and sometimes grungy (from a TDD perspective), code base, I'd love to hear about it. (*) By "legacy" I mean code that was not written with a test-driven development mindset. -- Chris Cleeland

On 17/01/2012 16:18, Chris Cleeland wrote:
(...)
What I found in my situation, though, was that mocking took a substantial amount of development effort in a "legacy"(*) body of code such that creating tests that rely upon mocking was more trouble than it was worth at first evaluation, i.e., it did not save me more time than it cost. As this was my first experience with an actual mocking framework (as opposed to ad-hoc bespoke stuff created for a single purpose), I'm not sure if it's a framework issue, a user (me) issue, an impedance mismatch between the framework and legacy code, or what. I suspect that the reality is that it's a little of all of them.
If anybody knows a mocking framework that slides easily into existing, and sometimes grungy (from a TDD perspective), code base, I'd love to hear about it.
(*) By "legacy" I mean code that was not written with a test-driven development mindset.
Hi Chris, I don't have the answer to your question but if your legacy code was developed with "traditional" unit tests, or even without tests, it isn't going to be easy to introduce mock objects because it actually means turning everything upside-down. Using mock objects tends to drive the code to be more "push" (ask others to do things) and less "pull" (collect data in order to do things) than the usual. Most of the test cases don't even check any results in the end, they just expect calls. It's not just a convenient way of faking components in order to test them more easily, it's also a way of driving the code a bit differently. From my experience, trying to use mock objects after a component has been written results in lengthy test cases which need to configure many mock objects and/or many expectations in order to work. I have seen for instance tests like this : BOOST_AUTO_TEST_CASE( some_test ) { some_mock a; MOCK_EXPECT( a.get_some_data ).once().with( -100.f, 100.f ).returns( 0 ); MOCK_EXPECT( a.get_some_data ).once().with( 0.f, 100.f ).returns( 1 ); MOCK_EXPECT( a.get_some_data ).once().with( 100.f, 100.f ).returns( -1 ); // etc... for A LOT of lines some_class b( a ); b.do_something( 12, 42, 77 ); BOOST_CHECK_EQUAL( 654, b.result() ); } This is indeed cumbersome to write and hard to maintain, and to someone accustomed to TDD it's a smell this most likely wasn't. :) My usual approach is either scrap the component and start from scratch, or just leave it be if it doesn't impact much the rest of the system... Mathieu

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

<snip>
on Thu Jan 19 2012, Mathieu Champlon
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,
Thanks for this very complete rundown! -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On 1/7/2011 12:35 PM, Dave Abrahams wrote:
At Fri, 07 Jan 2011 14:44:18 +0000, Mathieu Champlon wrote:
I wrote and use quite extensively http://turtle.sourceforge.net It still requires some work (and probably 2 or 3 total rewrites in the process :p) but it meets my needs and overall works better than the library I was using previously http://mockpp.sourceforge.net
<applause>
That looks like a pretty nice facility.
Agreed. Is this something you're eventually planning to submit for review?

2011/1/5 doug livesey
Hi -- I'm trying to learn to develop properly with C++ and Boost, and to that end am learning along with Boost.Test, as I'm a BDD coder in another language (Ruby) in my day job. I'm at the point, now, where my tests could really benefit from a mocking framework. There doesn't appear to be one in Boost (not documented, at least), so I wondered if anyone on the list could recommend a mocking framework that they use that works well with Boost.Test? Any and all advice gratefully received, Doug. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, I'm using Google Mock. It's quite powerful and in my opinion very clear. But you have to write some glue code to make it work with Boost Test. Something like this: class BoostTestAdapter: public EmptyTestEventListener { virtual void OnTestPartResult(const TestPartResult& testPartResult); { if (testPartResult.failed()) { std::stringstream s; if (testPartResult.file_name()) { s << std::endl << testPartResult.file_name() <<"(" << testPartResult.line_number() << "): " << testPartResult.summary(); } else { s << std::endl << "unknown file: " << testPartResult.summary(); } BOOST_ERROR(s.str()); } } }; struct GoogleMockFixture { GoogleMockFixture::GoogleMockFixture() { InitGoogleMock(&boost::unit_test::framework::master_test_suite().argc, boost::unit_test::framework::master_test_suite().argv); TestEventListeners &listeners = UnitTest::GetInstance()->listeners(); delete listeners.Release(listeners.default_result_printer()); listeners.Append(new BoostTestAdapter); } ~GoogleMockFixture() {} }; BOOST_GLOBAL_FIXTURE(GoogleMockFixture) The error reporting is not perfect yet, but usually you get the source file and line of the error directly in the error message. Hope that helps! Peter

On Fri, 07 Jan 2011 19:42:26 +0100, Peter Goetz
[...]I'm using Google Mock. It's quite powerful and in my opinion very clear. But you have to write some glue code to make it work with Boost
I can also recommend Google Mock. As it's based on Google Test which is similar to Boost.Test (basically the same macros with different names) I've used both Google libraries successfully in projects where I needed a mocking framework. Boris
[...]

Hi, first of all, thank you Peter! Your solution helped me a lot and based on your solution, I've made mine and I'd like to share. http://pastebin.com/QDh3ck8g This is it. Paulo Márcio -- View this message in context: http://boost.2283326.n4.nabble.com/Recommended-mock-framework-to-use-with-Bo... Sent from the Boost - Users mailing list archive at Nabble.com.

Hey Paolo,
I'm glad I could help. I'm not very familiar with the implementation
details of boost test, but I assume that your solution gives much
nicer error reporting? (Unfortunately I can't try it out right now)
Cheers,
Peter
Am 24. Februar 2012 13:44 schrieb paulo.alves
Hi, first of all, thank you Peter! Your solution helped me a lot and based on your solution, I've made mine and I'd like to share. http://pastebin.com/QDh3ck8g This is it.
Paulo Márcio
-- View this message in context: http://boost.2283326.n4.nabble.com/Recommended-mock-framework-to-use-with-Bo... Sent from the Boost - Users mailing list archive at Nabble.com. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (9)
-
Boris Schaeling
-
Chris Cleeland
-
Dave Abrahams
-
doug livesey
-
Joel Falcou
-
Kenny Riddile
-
Mathieu Champlon
-
paulo.alves
-
Peter Goetz