Alex Rivera | Logout

Unit testing with network-reliant code

Asked 2008-09-04T18:00:02.040
10

I'm trying to be better about unit testing my code, but right now I'm writing a lot of code that deals with remote systems. SNMP, WMI, that sort of thing. With most classes I can mock up objects to test them, but how do you deal with unit testing a real system? For example, if my class goes out and gets the Win32_LogicalDisk object for a server, how could I possibly unit test it?

Edit
Report

1 Answer

1

You might create a set of "test stubs" that replace the core library routines and return known values, perhaps after suitable delays.

As an example, I recently needed to develop code to run inside a 3rd-party product. The challenge was that our "partner" would be doing the compiling and integration with their base code: I wasn't allowed to look at their code in any form! My strategy was to build a very simple emulator that did what I thought their code did, based on information from their engineers. We used a language that made it easy to switch various pieces of the emulator in and out of each build, so I could do a tremendous amount of testing before involving our partner to build each new iteration.

I'd use the same method again, as software problems in that particular product are about an order of magnitude fewer than in our next most reliable product!

answered 2008-11-02T04:24:19.550

Your Answer