Boost::test and mocking framework [closed]

こ雲淡風輕ζ 提交于 2019-12-22 04:03:55

问题


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


回答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.




回答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.




回答3:


You can try Turtle !




回答4:


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




回答5:


GoogleMock has a section on using with another framework.




回答6:


ELFSpy let's you replace (mock) functions, methods, virtual functions etc with alternate implementations at runtime.

https://github.com/mollismerx/elfspy/wiki



来源:https://stackoverflow.com/questions/6759560/boosttest-and-mocking-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!