Dirty Little Secret: Test code is fun to write

| 0 Comments

I've been busy :( but it's paid busy so I suppose I can't complain...

This evening I got some time to myself to finally sit down and see how hard it would be to use all of my previous test code plus the real production POP3 server and command parser to act as a test framework for my POP3 client.

It took just over an hour to plug it all together and then it just kinda worked...

Way back when I decided that rather than try and build a mock server to test my POP3 client against I'd use the real one. In effect I would take the code that supported the tests of the POP3 server (a mocked up, controllable message store), plug it into the server, plug the server into the command parser and then just connect the client's output to the server's input and the server's output to the client's input. Given this arrangement I could develop the client test first without having to bother writing loads of supporting code. Woo hoo! What's more the client tests would also put the command parser and the server through their paces...

So I finally started tonight and it was easy and fun :)

Pretty much all I needed to write was a IInputStream to IOutputStream connector (in effect, a pipe; what goes in, comes out) and a convenience class, with a real mouthful of a name (CMockPOP3ServerSideInfrastructure) to tie everything together. Plug, plug, pluggedy, plug and it all works.

Now I can concentrate on parsing the output of the server.

The thing that was interesting was that writing this code was fun; it was an interesting little problem to solve at a time when the actual "production" code was looking pretty dull. It also meant that I had to use my server and command parser in a way I wasn't expecting to; they just worked, the interfaces seemed right, I didn't get all upset that some muppet had written the code and it was really hard to do slightly non-standard things with...

So, here I am writing more code than I might do otherwise, and this extra code is fun to write! Remind me why we haven't done this test first stuff for years?

Leave a comment