Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost::test and mocking framework [closed]

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

like image 791
Sardathrion - against SE abuse Avatar asked Jul 20 '11 09:07

Sardathrion - against SE abuse


2 Answers

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.

like image 90
Eran Pe'er Avatar answered Nov 02 '22 23:11

Eran Pe'er


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.

like image 28
Gyan aka Gary Buyn Avatar answered Nov 03 '22 00:11

Gyan aka Gary Buyn