( ... a few things I picked up in Naples ... Ed Crewe ILRT Oct 2007)
Testing in Plone - Tutorial on plone.org
When you create a new site with Plone, the least you should do is create a policy product.
Now zope uses eggs ... python jars which package up the Product(s) with their python dependencies and version compatibility. Use the egg paster utility to create a plone style egg ...
> $PYTHON_HOME/bin/paster create -t plone mynewsite.policy
- ready for installation via the zope buildout deployment mechanism (developed as part of the zope3 grok framework).
NB: These eggs are kept in a repository now rather boringly called the python package index which was called the cheeseshop ... and there is an emerging cheesecake system that is used to check if your code is good - no tests = inedible cake!
So the standard zope server now has all the testing framework for unit, functional, regression and doctests built in .... why not install Plone3 and have a look ...
Well we would all like to be good developers and follow test driven development practice ... and I am sure we all will with our new sites ... which will be products in subversion with full coverage tests ... but even if you can't start writing tests tommorrow, the following are good starting points:
Write your own tests
If you do any customisation to Plone, you have to write some stylesheets, code, etc. You should then put it into a versioning system ... unless you are a God who never needs to undo anything
Of course even the most minimal customisation of Plone should be done as a product, so that it can be deployed.
Once you are at this stage you should be writing tests to check the product code.
.Funkload is a great utility for recording functional tests, but it is much more than that.
It can run any type of tests and hence be integrated with high level doctests, unit tests or use low level pdb
Along with running the tests in can do so as multiple users, to provide graphical benchmarking information out of all the tests mentioned above ... hence check whether your production site will actually cope with predicted usage.
NB: At Bristol we use MRTG and Munin to graph system load on the CMS server farm, to anticipate overall load issues, and perl scripts for peak page view load testing (~ 50 requests per sec) ... but with Funkload we could better check the overhead of new features, products and related usage patterns, before they are rolled out.
The following demos how you would use it to record a functional test ... editing a page, adding another and publishing.
Installation is well documented but involved, my browser needs to be set to go via a TCPWatch proxy. Once done, I can just run the following:
> fl-record add_page
I go to the site I want to record my test from and do my edit, add and publish in Firefox. I can then replay this and get timing information
> fl-run-test -dV test_AddPage.py
Files fl-record generates: add_page-test.log | add_page-test.xml | test_AddPage.py
Now lets do some functional load test benchmarking with my macro created test case ... using 1, 5, 10 and 20 concurrent users ...
> fl-run-bench -c 1:5:10:20 test_AddPage.py AddPage.test_add_page
Files fl-run-bench generates: add_page-bench.log | add_page-bench.xml
We want to generate nice HTML report from our benchmarking XML data file ...
> fl-build-report --html -o /var/www/htdocs/funkload add_page-bench.xml
So lets have a look at it ...
/testing/test_add_page-2007-10-19T12-59-08/index.html
Ooooh isn't it pretty ... but urrggh look how the successful requests drop between 10 and 20 concurrent users!
For a full step by step guide see Martin Aspeli's tutorial
and his book is also based on test driven development.
I also attended the Naples talk on testing given by Untested code is Broken code by Philipp von Weitershausen and Martin Aspeli. Which evangelised test driven development.
PS: I should perhaps come clean here and say I have only written unit tests as part of java projects ... so I am a novice in the python world of unit testing myself. However in order to bring our code base back into line with Plone 3, and benefit from the new frameworks, plus start releasing Products, we have to get on board with testing. Which will hopefully have the many side benefits such as stopping nasty surprises and aiding productivity and consistency across our growing number of Plone developers.