[TIP] Getting started writing DocTests for Web applications
olemis at gmail.com
Wed Feb 4 05:29:08 PST 2009
Hello once again ... ;)
On Wed, Jan 21, 2009 at 4:47 PM, Fran Boon <flavour at partyvibe.com> wrote:
> Olemis Lang wrote:
> ok, I have managed to get some basic doctests running fine in this style
> using CherryPy's WebTest.
> Create a simple module 's3_test':
> import wsgi_intercept.webtest_intercept
> class WSGI_Test(wsgi_intercept.webtest_intercept.WebCase):
> Then in the doctests (in Controllers):
> >>> from s3_test import WSGI_Test
> >>> test=WSGI_Test()
> >>> '200 OK' in test.getPage('/sahana/cr/shelter')
> >>> test.assertHeader("Content-Type", "text/html")
> >>> test.assertInBody('List Shelters')
> >>> '200 OK' in test.getPage('/sahana/cr/shelter?format=csv')
> >>> test.assertHeader("Content-Type", "text/csv")
IMO ... the real power in using doctests is as follows :
- to test the target library (... framework / app ...)
- reuse all this work to reveal how the library (... framework / app ...) works
and how users should use it ... providing them with concrete yet simple
examples of how to do so.
I dont see the point (... CMIIW ...) for writing the aforementioned
doctests, since its not informative at all. I mean once people reads
all that, they still have no idea about how the target library (...
framework / app ...) works ... So IMO once again I'd do it like if I
was writing unittests and write this kind of things in a separate test
module. Next I'd load each test using the appropiate TestLoaders or
relying on the functionality provided by a framework.
Besides ... I think there is a bizarre combination of unittest +
doctest in the previous code snippet ... the doctests should not work
since setup (... and also tearDown ;) methods have not been called,
and since this is not «the most convenient» way of writing doctests
together with unittests ... AFAIK ... and also IMO ... ;)
> This is useful, but I can't seem to add support for the database calls so
> hard to extend this further.
Once I have twill up and running ... I'll try to combine unittests +
doctests ... but as I told you before ... twill's not working ... :(
> Right now I'm focussing on a different approach: Selenium
I've not used it ... yet ... but I hope I can try it ... in near future ...
... now ... time's over ... :(
Good luck !
Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/
More information about the testing-in-python