[Checkins] SVN: Sandbox/philikon/zopeproject/trunk/ Functional test
boiler plate
Philipp von Weitershausen
philikon at philikon.de
Sat Sep 15 17:46:13 EDT 2007
Log message for revision 79681:
Functional test boiler plate
Changed:
U Sandbox/philikon/zopeproject/trunk/README.txt
U Sandbox/philikon/zopeproject/trunk/TODO.txt
U Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/setup.py_tmpl
A Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/src/+package+/ftesting.zcml_tmpl
A Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/src/+package+/testing.py_tmpl
-=-
Modified: Sandbox/philikon/zopeproject/trunk/README.txt
===================================================================
--- Sandbox/philikon/zopeproject/trunk/README.txt 2007-09-15 16:51:06 UTC (rev 79680)
+++ Sandbox/philikon/zopeproject/trunk/README.txt 2007-09-15 21:46:12 UTC (rev 79681)
@@ -254,6 +254,60 @@
$ bin/buildout
+Writing and running tests
+=========================
+
+Automated tests should be placed in Python modules. If they all fit
+in one module, the module should simply be named ``tests``. If you
+need many modules, create a ``tests`` package and put the modules in
+there. Each module should start with ``test`` (for example, the full
+dotted name of a test module could be ``myzopeapp.tests.test_app``).
+
+If you prefer to separate functional tests from unit tests, you can
+put functional tests in an ``ftests`` module or package. Note that
+this doesn't matter to the test runner whatsoever, it doesn't care
+about the location of a test case.
+
+Each test module should define a ``test_suite`` function that
+constructs the test suites for the test runner, e.g.::
+
+ def test_suite():
+ return unittest.TestSuite([
+ unittest.makeSuite(ClassicTestCase),
+ DocTestSuite(),
+ DocFileSuite('README.txt', package='myzopeapp'),
+ ])
+
+To run all tests in your application's packages, simply invoke the
+``bin/test`` script::
+
+ $ bin/test
+
+Writing functional tests
+------------------------
+
+While unit test typically require no or very little test setup,
+functional tests normally bootstrap the whole application's
+configuration to create a real-life test harness. The configuration
+file that's responsible for this test harness is ``ftesting.zcml``.
+You can add more configuration directives to it if you have components
+that are specific to functional tests (e.g. mockup components).
+
+To let a particular test run inside this test harness, simply apply
+the ``myzopeapp.testing.FunctionalLayer`` layer to it::
+
+ from myzopeapp.testing import FunctionalLayer
+ suite.layer = FunctionalLayer
+
+You can also simply use one of the convenience test suites in
+``myzopeapp.testing``:
+
+* ``FunctionalDocTestSuite`` (based on ``doctest.DocTestSuite``)
+
+* ``FunctionalDocFileSuite`` (based on ``doctest.DocFileSuite``)
+
+* ``FunctionalTestCase`` (based on ``unittest.TestCase``)
+
Debugging
=========
Modified: Sandbox/philikon/zopeproject/trunk/TODO.txt
===================================================================
--- Sandbox/philikon/zopeproject/trunk/TODO.txt 2007-09-15 16:51:06 UTC (rev 79680)
+++ Sandbox/philikon/zopeproject/trunk/TODO.txt 2007-09-15 21:46:12 UTC (rev 79681)
@@ -5,8 +5,6 @@
* Allow values to be provided thru command line arguments
See https://bugs.launchpad.net/grok/+bug/125817.
-* ftesting.zcml and testing.py
-
* Need tests!
* README: how to deploy?
Modified: Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/setup.py_tmpl
===================================================================
--- Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/setup.py_tmpl 2007-09-15 16:51:06 UTC (rev 79680)
+++ Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/setup.py_tmpl 2007-09-15 21:46:12 UTC (rev 79681)
@@ -42,6 +42,11 @@
'zope.app.intid',
'zope.app.keyreference',
'zope.app.catalog',
+ # The following packages are needed for functional
+ # tests only
+ 'zope.testing',
+ 'zope.app.testing',
+ 'zope.app.securitypolicy',
],
entry_points = """
[console_scripts]
Added: Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/src/+package+/ftesting.zcml_tmpl
===================================================================
--- Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/src/+package+/ftesting.zcml_tmpl (rev 0)
+++ Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/src/+package+/ftesting.zcml_tmpl 2007-09-15 21:46:12 UTC (rev 79681)
@@ -0,0 +1,50 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta"
+ i18n_domain="${package}">
+
+ <!-- Turn on the devmode -->
+ <meta:provides feature="devmode" />
+ <include package="${package}" />
+
+ <include package="zope.app.securitypolicy" file="meta.zcml" />
+ <include package="zope.app.securitypolicy" />
+ <securityPolicy
+ component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+ <!-- Test Principals -->
+
+ <unauthenticatedPrincipal id="zope.anybody"
+ title="Unauthenticated User" />
+ <unauthenticatedGroup id="zope.Anybody"
+ title="Unauthenticated Users" />
+ <authenticatedGroup id="zope.Authenticated"
+ title="Authenticated Users" />
+ <everybodyGroup id="zope.Everybody"
+ title="All Users" />
+
+ <!-- Principal that tests generally run as -->
+ <principal
+ id="zope.mgr"
+ title="Manager"
+ login="mgr"
+ password="mgrpw"
+ />
+ <!-- Bootstrap principal used to make local grant to the principal above -->
+ <principal
+ id="zope.globalmgr"
+ title="Manager"
+ login="globalmgr"
+ password="globalmgrpw"
+ />
+
+ <grant permission="zope.View"
+ principal="zope.Anybody" />
+ <grant permission="zope.app.dublincore.view"
+ principal="zope.Anybody" />
+
+ <role id="zope.Manager" title="Site Manager" />
+ <role id="zope.Member" title="Site Member" />
+ <grantAll role="zope.Manager" />
+ <grant role="zope.Manager" principal="zope.globalmgr" />
+
+</configure>
Added: Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/src/+package+/testing.py_tmpl
===================================================================
--- Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/src/+package+/testing.py_tmpl (rev 0)
+++ Sandbox/philikon/zopeproject/trunk/zopeproject/zope_app/src/+package+/testing.py_tmpl 2007-09-15 21:46:12 UTC (rev 79681)
@@ -0,0 +1,23 @@
+import os.path
+import ${package}
+from zope.testing import doctest
+from zope.app.testing import functional
+
+ftesting_zcml = os.path.join(
+ os.path.dirname(${package}.__file__), 'ftesting.zcml')
+FunctionalLayer = functional.ZCMLLayer(ftesting_zcml, __name__,
+ 'FunctionalLayer')
+
+def FunctionalDocTestSuite(module=None, **kw):
+ module = doctest._normalize_module(module)
+ suite = functional.FunctionalDocTestSuite(module, **kw)
+ suite.layer = FunctionalLayer
+ return suite
+
+def FunctionalDocFileSuite(path, **kw):
+ suite = functional.FunctionalDocFileSuite(path, **kw)
+ suite.layer = FunctionalLayer
+ return suite
+
+class FunctionalTestCase(functional.FunctionalTestCase):
+ layer = FunctionalLayer
More information about the Checkins
mailing list