Boost::test and mocking framework

14,706

Solution 1

I recently did a search for unit testing and mocking frameworks for my latest project and went with Google Mock. It had the best documentation and seems fairly well featured (although I haven't created very complex mock objects yet). I initially was thinking of using boost::test but ended up using Google Test instead (I think it's a prerequisite for Google Mock, even if you use another testing framework). It also has good documentation and has had most of the features I expected.

Solution 2

Fake-It is a simple mocking framework for C++ uses the latest C++11 features to create an expressive (yet very simple) API. With FakeIt there is no need for re-declaring methods nor creating a derived class for each mock and it has a built-in boost::test integration. Here is how you Fake-It:

struct SomeInterface {
  virtual int foo(int) = 0;
};

// That's all you have to do to create a mock.
Mock<SomeInterface> mock; 

// Stub method mock.foo(any argument) to return 1.
When(Method(mock,foo)).Return(1);

// Fetch the SomeInterface instance from the mock.
SomeInterface &i = mock.get();

// Will print "1"
cout << i.foo(10);

There are many more features to explore. Go ahead and give it a try.

Solution 3

Here you've got an example of using Google Mock with Boost Test. I prefer Boost Test because I use other Boost libraries often.

Solution 4

You can try Turtle !

Solution 5

GoogleMock has a section on using with another framework.

Share:
14,706
Sardathrion - against SE abuse
Author by

Sardathrion - against SE abuse

I am deeply saddened and worried by the abusing behaviour of stack exchange staff with regards to its users and have stopped all activities in this network. I urge you to do educate yourselves before it is too late. The final words… Firing mods and forced relicensing: is Stack Exchange still interested in cooperating with the community? Time line of events Sign the open letter, if you wish… I did. Nescire autem quid ante quam natus sis acciderit, id est semper esse puerum. Quid enim est aetas hominis, nisi ea memoria rerum veterum cum superiorum aetate contexitur? -- Cicero, Marcus Tullius (106-43BC)

Updated on June 04, 2022

Comments

  • Sardathrion - against SE abuse
    Sardathrion - against SE abuse almost 2 years

    I am using boost::test and need to use a mocking framework with it. Does anyone have any recommendations?

  • Peter DeWeese
    Peter DeWeese over 12 years
    What are the advantages to Turtle?
  • Ioanna
    Ioanna almost 8 years
    Well, it's easily integrated with boost::test: you won't need all the workarounds that are required to make a boost::test project use gmock, for example (see also stackoverflow.com/questions/38890959/…).
  • Ioanna
    Ioanna almost 8 years
    Indeed, but it is still memory-leak-prone and requires workarounds: stackoverflow.com/questions/38890959/…
  • Eric M
    Eric M about 5 years
    Turtle's documentation is terse to the point of being null. I don't think it is an advantage. Turtle is hard to use.
  • Mariusz Jaskółka
    Mariusz Jaskółka about 4 years
    The link is dead