12

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)?
abatishchev
  • 98,240
  • 88
  • 296
  • 433
hate-engine
  • 2,300
  • 18
  • 26

1 Answers1

7

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

Torsten Robitzki
  • 3,041
  • 1
  • 21
  • 35
  • Hi, I've been looking at unit testing boost::asio as well and found your test_socket.h, I'm borrwing it if you don't mind :) – dutt Jan 01 '14 at 08:27
  • 3
    @dutt You're welcome to use it. Have a look at https://github.com/TorstenRobitzki/Sioux/tree/master/source/asio_mocks, where I've tried to put this in a more reusable form. – Torsten Robitzki Jan 02 '14 at 12:31
  • Thanks, I'll take a look :) I've made some slight modifications here to suit my needs. – dutt Jan 02 '14 at 17:21
  • @TorstenRobitzki You might consider that you told people to use that file, but the current version says at the top: // Copyright (c) Torrox GmbH & Co KG. All rights reserved. // Please note that the content of this file is confidential or protected by law. // Any unauthorised copying or unauthorised distribution of the information contained herein is prohibited. Maybe a different copyright license would be appropriate? – jonesmz Oct 01 '19 at 20:27
  • Any pull request, that deletes this copyright text, will be accepted. – Torsten Robitzki Oct 02 '19 at 21:26