Currently I do it this way (pseudocode):
#include <boost/test/unit_test.hpp>
#include <string>
bool testingClient = true;
BOOST_AUTO_TEST_SUITE(ProtocolSchema)
BOOST_AUTO_TEST_CASE(server)
{
testingClient = false;
// start server listener
FILE *client_stdout = popen((argv[0] + std::string(" --run_test=ProtocolSchema/client 2>&1")).c_str(), "r");
for (1000ms)
{
// listen for ping, reply with a pong
}
pclose(fl);
}
BOOST_AUTO_TEST_CASE(client)
{
if (!testingClient)
return;
// send ping to the server
// check that it replies with a pong
}
}
The idea is clear: boost::test
runs tests sequentially, once it tries to run server, the server unit test flips testingClient
this way next test simply doesn't do anything and exits. server test starts the same test executable with run_test
arg set to run client test only. In the second process testingClient
flag isn't flipped, this makes it actually run client test.
Is there a proper way to do this kind of client-server unit testing with boost::test? In my case all the test logging from client process are kind of lost: I'd need to fread them from client_stdout and then perhaps write it all to BOOST_MESSAGE?