Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Mock/Test boost::asio::io_stream - based Asynch Handler

I've recently returned to C/C++ after years of C#. During those years I've found the value of Mocking and Unit testing.

Finding resources for Mocks and Units tests in C# is trivial. WRT Mocking, not so much with C++.

I would like some guidance on what others do to mock and test Asynch io_service handlers with boost.

For instance, in C# I would use a MemoryStream to mock an IO.Stream, and am assuming this is the path I should take here.

  • C++ Mock/Test best practices
  • boost::asio::io_service Mock/Test best practices
  • C++ Async Handler Mock/Test best practices

I've started the process with googlemock and googletest.

like image 965
rbellamy Avatar asked Mar 11 '10 16:03

rbellamy


1 Answers

As you've probably found already, there's much less help for mocking in C++ than in C# or Java. Personally I tend to write my own mocks as and when I need them rather than use a framework. Since most of my designs tend to be heavy on the interfaces this isn't especially difficult for me and I tend to build up a 'mock library' that goes with the code that I'm developing. An example of how I do things can be found here in my 'Practical testing' articles. In the end it's not that different to mocking and testing in C#, all of the same principles apply, you just end up doing more of the heavy lifting yourself.

like image 122
Len Holgate Avatar answered Sep 19 '22 17:09

Len Holgate