views:

39

answers:

1

I'm using Boost.Test for Unit testing and am currently running various mock servers in separate threads which get launched from within each test. In order to more accurately test my code the mock server's should really be in separate processes.

I was thinking about doing something along these lines:

MY_TEST()
if (fork() == 0) {
    runMockServer();  // responds to test requests or times out, then returns
    exit(0);
}
// Connect to MockServ and Run actual test here
END_TEST()

but I'm worried that this will screw up the testing framework.

Is this safe? Has anyone done something like this?

I'm using Boost 1.34.1 on Ubuntu 8.04 if that matters.

+2  A: 

This doesn't really sound like unit-testing for what you want to achieve. Though I don't see why it would not be safe. You may have a race condition where your unit test connects to the MockServ if it isn't ready yet, but that is easily solvable.

I've never done something like this directly, but I have written unit tests for libraries that fork/exec child processes and it works flawlessly.

Sam Miller
When you say you've, "written unit tests for libraries that fork/exec" I assume you mean in the context of Boost.Test?
Robert S. Barnes
correct, using Boost.Test.
Sam Miller
Thanks. Out of curiosity, why would you say this doesn't sound like unit testing you?
Robert S. Barnes
It's mostly splitting hairs, but I consider testing an entire process integration or functional testing.
Sam Miller