Unit testing
Unit testing is the process of writing small programs that test the specific functions of small units of the software. These programs are then run to make sure that your changes hasn't broken any functionality. Some philosophies recommend that you write the unit tests before you write the functionality, so called test-driven development.
About unit tests:
- Test Infected by Kent Beck and Erich Gamma.
- Unit tests as a part of the extreme programming paradigm
- Test driven development, a book by Kent Beck
Writing unit tests
Some guidance on how to write unit tests.
- http://agiletesting.blogspot.com - a must-read for python coders doing testing.
- Zope Product Developer's Guide: Zope Unit Testing
- Zope Developer's Guide: Chapter 7, Testing and Debugging
- http://dev.zope.org/CVS/ZopeTestingGuidelines
- http://dev.zope.org/Wikis/DevSite/Proposals/CleanUpAndUnifyCoreUnitTests
Test frameworks
When you write unit tests you typically use some sort of testing framework, to make it easier to write and run the tests. The Zope testing framework is based on Python's PyUnit. There are, however, some extended frameworks that you probably want to use to simplify test development:
- ZopeTestCase, for any Zope development.
- CMFTestCase?, for CMF development.
- PloneTestCase?, for Plone development
- CPSTestCase? for CPS development (extends ZopeTestCase).
Note, however, that these frameworks work by putting quite a bit of the real Zope system and/or CMF, Plone, etc. in place for you; therefore, some consider them integration tests (see below) rather than true unit tests.
Pure unit tests should have as few dependencies as possible, and may rely heavily on MockObjects.
Running unit tests
- HowToRunZopeUnitTests
- [Zope3]:HowToRunZopeUnitTests
Integration tests
Integration tests are tests which combine various parts of your application and ensure that they work together properly. For example, if you have skin scripts which glue together various CMF tools, then a test of such a script might be considered an integration test.
Integration tests happen at a lower level than functional tests, but a higher level than unit tests.
Resources for integration test:
ZopeTestCase.Functional, http://www.zope.org/Members/shh/ZopeTestCaseWiki/FunctionalTesting
You may find TestLayers a useful technique for complex setup and teardown.
Functional tests
Functional testing is done on the end product (in this case on a web site) usually by recording actions of a user and recording the output of these actions. This recordings can then be replayed by the functional testing software, and the output compared to what should happen.
Resources for functional tests:
- Tres Seaver's FunctionalTests product provides support for writing functional tests, especially if you use ZEO.
- Puffin (NB: Puffin hasn't changed for 19 months).
- [Zope3]:FunctionalTestingFramework
More testing resources:
- Python Testing Tools Taxonomy
- The Nlpi Test Architecture
- Literate Testing - Automated Testing with doctest (pycon 2004)
- Adept , a declarative test framework (pycon 2004)
- mechanize support in CMFPlone?/ftests
- http://awkly.org/Members/sidnei/weblog_storage/blog_32471
- http://docs.neuroinf.de/programming-plone/testing
- Zope 3 Developer's Book : G. Writing Tests