Protocol Testing with Doctests

A couple of years ago I was asked to write some tests (and maybe test framework, I can’t remember) for Cosmo, the Chandler Server. I think the only tools we had used for testing until then were litmus and manual testing, maybe with some unit tests. The protocols to be tested include ticket, CMP etc. protocols.

The thought of expanding litmus, which was a tool written in C, did not sound too promising. Command line tool to test the protocol was also what we were mainly after at that point, so GUI tools were not needed. And it was going to be easier to automate command line tools with Tinderbox.

Around that time I had been really sold on doctests, so I figured by writing some helper functions the protocol tests for Cosmo could be done easily as Python doctests. Developing the “framework” was fast, I was testing within minutes, and probably the time spent on the helper functions still amounts to less than a day, total. I based the helper functions on httplib, but urllib2 or httplib2 would probably make the experience even easier. I named the tool “silmut” , which is an anagram of litmus, and also a word in the Finnish language, meaning “buds”.

In the end we collected each protocol’s tests into its own file. At the top we had some code to do common initialization, and after that followed the actual tests. Here’s an example of a test:

View account
    >>> r = request('GET', '%s/cmp/user/%s' % (path, user1), headers=authHeaders)
    >>> r.status # GET account ok

I was actually surprised to note that these tests are still in the Cosmo sources, and apparently being maintained. Just goes to show you don’t always need to be too fancy to get the job done.

Similar Posts:

    None Found

One Comment

  1. drewp:

    You might also like which is another doctest+REST system with more specific syntax. I think it goes a bit too far with magic restructured-text tricks, though.