[TIP] Getting started writing DocTests for Web applications
Fran Boon
flavour at partyvibe.com
Wed Jan 21 13:47:42 PST 2009
Olemis Lang wrote:
> it is particularly useful to write doctests and load
> them like if you were using unittest ... with some beneficial
> side-effects, like storing the evaluation of a single interactive
> example in a single TestResult instance, and a few more ... ;)
>> Inspired by this post:
>> http://agiletesting.blogspot.com/2006/04/in-process-web-app-testing-with-twill.html
> This is great ... I'll try to write a simple test like the one
> mentionned in this article, but using dutest ... I'll let you know
> about the results once I run a test suite so as to tell you about the
> details ... hopefully soon ;)
Sounds good - looking forward to seeing simple examples :)
>> I'll report back when I've started to make real progress...
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):
HTTP_CONN = wsgi_intercept.WSGI_HTTPConnection
HOST = 'localhost'
PORT = 8000
def __init__(self):
"Copy Intialise"
wsgi_intercept.webtest_intercept.WebCase.__init__(self)
return
def setUp(self):
"Hook into the WSGI process"
wsgi_intercept.add_wsgi_intercept(self.HOST, self.PORT, create_fn)
return
def runTest(self):
"Mandatory method for all TestCase instances"
return
Then in the doctests (in Controllers):
>>> from s3_test import WSGI_Test
>>> test=WSGI_Test()
>>> '200 OK' in test.getPage('/sahana/cr/shelter')
True
>>> test.assertHeader("Content-Type", "text/html")
>>> test.assertInBody('List Shelters')
>>> '200 OK' in test.getPage('/sahana/cr/shelter?format=csv')
True
>>> test.assertHeader("Content-Type", "text/csv")
This is useful, but I can't seem to add support for the database calls
so hard to extend this further.
I tried to refactor into a UnitTest, but that isn't working currently
either.
Right now I'm focussing on a different approach: Selenium
I have integrated Selenium core into the application which works
beautifully.
We can use make_selenium.py to develop the scripts in Python yet execute
in TestRunner:
http://joker.linuxstuff.pl/documentation/make_selenium
I next want to capture the results for display in Bitten.
Anyone have a postresults.py?
I am looking to see if I can de-Plone this one:
http://jrandolph.com/selenium-plone/selenium-0.3rc2-plone.zip
or convert this PHP one:
http://wiki.openqa.org/display/SEL/Integrating+Selenium+And+CruiseControl.Net
I also have Selenium RC working with the same tests (help from:
http://groups.google.com/group/web2py/msg/d8c9fd6008029f6b)
Although the export from Selenium IDE doesn't like my custom
user-extensions.js...need to talk to Selenium flks about that :/
This can then be potentially used by a Bitten-slave (on machines with
graphical browsers anyway ;) )
Comments on this approach welcomed - what do I lose by focussing on
Selenium?
The in-process testing?
Coverage?
F
More information about the testing-in-python
mailing list