views:

229

answers:

3

I've never managed to move from unit-testing to integration-testing in any graceful or automated way when it comes to network code.

So my question is: Given a simple single-threaded client/server based network application, how would you go about integrating both client and server into your currently favorite testing suite (I currently use check).

I am of course willing to change unit-test suite to accomplish my goal.

Edit: While I appreciate the answers, I was more looking for some magical way of integrating integration-testing into my unit-test framework (if it's possible at all). Like if fork() or something could be applied without getting too many side effects.

A: 

We structure our applications so that the core code is in a library and the executable is generated from a main.c (really main.cxx in our case) that is just a very thin wrapper that starts the server or client. This lets us set up test suites that can instantiate a complete server and client in proc and do tests where they talk to one another using their normal network protocol. It works quite well.

If you can't structure things this way, you could start your usual server executable using fork/CreateProcess and then have the client code inside the test talk to the external server.

David Norman
+1  A: 

Another approach is to mock up both ends with a dummy server and dummy client that just send the messages that you want to test and verify the responses are as expected. These mock servers cab be really, really dumb: they only need to read/write sockets and dump pre-set data back. You can spiff them up a bit by templating the responses from data in the requests if it's easy to parse.

The win here is that you know exactly what the mocked item is going to do (including fake timeouts, send garbage, whatever you want).

It would probably be very easy to use a Perl or Python socket library to build your mock servers and clients; if you use Perl, you should be able to use the very capable Test:: classes from CPAN to help do the actual "did this work" and reporting.

Joe McMahon
A: 

netcat is a great tool for testing network servers and clients.

man netcat says that netcat is TCP/IP swiss army knife. Having experience with both netcat and Victorinox Swiss army knife I can assure you that netcat is much better than Victorinox - I'd rather compare it to Leatherman.

qrdl