views:

241

answers:

1

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.

+1  A: 

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.

Len Holgate
This is indeed helpful. It goes a long way to answering the first of my bullets. I was hoping for some direct guidance on how best to mock/test asynchronous I/O using boost::asio::io_service.
rbellamy
Sorry, I don't use ASIO, I have my own async I/O framework.
Len Holgate