2. Part 1 – Why testing matters
● Reduces defects
● Find bugs early
● Proof that you delivered what you were
contracted to produce
● Refactor with confidence
● Lots of small successes
4. What are you going to learn today?
● Set up integration and functional tests
● Traditional test setup
● Test setup with layers
● Testing
● Policy product
● Dexterity types
● Archetypes
● Portlets
22. Setting Up Tests with Layers:
layer.py
# Imports
ptc.setupPloneSite(
extension_profiles=('upc.testingtutorial:default', )
)
class IntegrationTestLayer(collective.testcaselayer.ptc.BasePTCLayer):
def afterSetUp(self):
self.addProfile('upc.testingtutorial:default')
Layer = IntegrationTestLayer([collective.testcaselayer.ptc.ptc_layer])
23. Setting Up Tests with Layers:
test_functional_doctest.py
# Imports
from upc.testingtutorial.tests.layer import Layer
def test_suite():
return unittest.TestSuite([
ztc.ZopeDocFileSuite(
'functional.txt', package='upc.testingtutorial.tests',
test_class=ptc.FunctionalTestCase,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE |
doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS),
])
24. Setting Up Tests with Layers:
functional.txt
==========================================
UPC Testing Tutorial: Functional Doctest
==========================================
This package contains a functional doctest for the task content type of the
upc.testringtutorial package. In this testbrowser doctest, we will demonstrate
how the task content type works. See tests/test_functional_doctest.py for how
it is set up.
>>> from Products.Five.testbrowser import Browser
>>> browser = Browser()
>>> portal_url = self.portal.absolute_url()
25. Setting Up Tests with Layers:
test_task.py
class TestTaskIntegration(PloneTestCase):
layer = Layer
def test_adding(self):
self.folder.invokeFactory('upc.testingtutorial.task', 'task1')
t1 = self.folder['task1']
self.failUnless(ITask.providedBy(t1))
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)