hate-engine
hate-engine

Reputation: 2350

Unit-testing and boost::asio

I'm writing small XMPP server using boost::asio and I want to unit-test my code. Questions:

  1. Are there some ready-to-use frameworks for this? As far as I understand, I need to provide mock objects for boost::asio classes/templates and I really want to make this (semi)automatically.
  2. Is it possible to test concurrency (e.g. multiple connections to server and message routing between them)?

Upvotes: 12

Views: 5450

Answers (1)

Torsten Robitzki
Torsten Robitzki

Reputation: 2555

1) I wrote a small socket class that can be used as a replacement for the boost::asio::ip::tcp::socket. If you like, you can have a look at robitzki.de/test_socket.h (test_socket.cpp, test_io_plan.h and test_io_plan.cpp). Depending on the constructor used, the socket can simulate reading/writing of chunks with different sizes. Errors can be simulated too. You are free to use it, if you like.

2) With the socket replacement one can build stress tests for the software under test. This will never guaranty that the code doesn't contain bugs but is better than nothing ;-). Personally I like code reviews best to make sure multithreaded code contains as few bugs as possible.

HTH

Torsten

Upvotes: 7

Related Questions