Ian Bicking: the old part of his blog

Zope 3 functional doctests

The Zope 3 project use something called "functional doctests". The idea is that you run tcpwatch and use your browser to create a functional test for your Zope 3 application. Then you run a small Python script that converts record files produced by tcpwatch into .txt files that contain embedded doctests, and include that file into your functional test suite.

We started using functional doctests for the SchoolTool/SchoolBell project. Here's an example test.

By the way, I've found it easier to write new tests with vim by copying and modifying existing tests, rather than starting up tcpwatch and doing it with a browser, but I suppose that depends on how geeky you are...

Comment on Web application acceptance testing
by Marius Gedminas

Comments:

Cool, that's just the kind of thing I was thinking of. It seemms a tad crude -- what with the raw requests right in the code. It seems like with a little care (plus something based on mechanize's stateful browser object) you could improve the narrative quality nicely. For instance (from your example):

>>> print http("""
... POST /frogpond/resources/lily/edit.html HTTP/1.1
... Authorization: Basic mgr:mgrpw
... Content-Length: 29
... Content-Type: application/x-www-form-urlencoded
...
... field.title=Foo&CANCEL=Cancel
... """)
HTTP/1.1 303 See Other
...
Location: http://localhost/frogpond/resources/lily
...

Might instead be:

>>> b.click('CANCEL')
>>> b.response.status
303 See Other
>>> b.response.headers.location
'http://localhost/frogpond/resources/lily'

Note that b (the browser object) specifically has knowledge of the context and the last request, so in this case you are submitting a form that you just received. I think this statefulness better represents the thing you are testing, plus doctests are sequential and narrative anyway -- might as well take advantage of it. In general I've thought that the Zope 3 doctests I've seen seemed like they didn't have enough scaffolding; there should be more helper functions written solely for the purpose of doctesting.

Anyway, it's still cool that it's useful and works for you. The XML doctest extension I wrote might also be useful for this sort of thing -- though it still needs wildcards.

# Ian Bicking

Due to some code restructuring in SchoolTool/SchoolBell, the example test link is now broken. Here's a working link to the same example test. This time I included a revision number as well, so this link should be permanent.

# Marius Gedminas