[clug] PSIG last night

David Tulloh david at tulloh.id.au
Mon Nov 17 12:31:25 GMT 2008

David Schoen wrote:
> On the subject of Unit Testing more generally, does anyone know if/how
> to Unit Test a queue/callback setup.
> Specifically I've got a FileManager class that I ask to queue files,
> from the web. At some point the FileManager class will call a
> predefened callback class, in this case TestManager, which works out
> if it actually has enough info to test a file now or if it has to
> queue more stuff in the FileManager and wait for more files to arrive
> before it can test anything.
> But the bit I'm stuck on is how do I test the queueing and the
> callback mechanism in the FileManager class with a Unit Test?
I tend to approach unit testing by first isolating the item under test.

In this case, I would start by simulating the internet portion.  How you 
do this really depends on how you are downloading the content, you could 
make a mock library or if you have to, tweak a basic web server and 
point at that.  The aim here is to have control of the input into the 
FileManager class.  Once you have done that you can simulate all your 
different conditions to form a set of tests.

The callback mechanism is a bit easier, mock up a TestManager class to 
accept the data and make it available to the test harness.

With the two combined your harness can send some data into your class 
and test that the callback is or isn't called.


More information about the linux mailing list