BlueBream The Web Component Framework

9.10. Functional Testing

9.10.1. Introduction

In this chapter, you will learn more about functional testing. A doctest based package (zope.testbrowser) is used in BlueBream for functional testing. Unlike unit tests, functional tests are user interface (view) oriented.

9.10.2. zope.testbrowser

The central part of this package is a browser object. This create this object, import Browser class from zope.testbrowser.testing:

>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()

To learn the usage of package, first create a simple HTML page with following content:

<html>
  <head>
    <title>Test Page</title>
  </head>
  <body>
    <h1>Test Page</h1>
  </body>
</html>

To open a page:

>>> browser.open('http://localhost/zopetest/simple.html')
>>> browser.url
'http://localhost/zopetest/simple.html'

9.10.3. Test layer

9.10.4. Running tests

Your test suites can be placed in tests.py module under each packages. By default, in BlueBream there will be a tests.py with one test suite created using z3c.testsetup:

import z3c.testsetup

test_suite = z3c.testsetup.register_all_tests('tc.main')

The z3c.testsetup will aut-recover test suites from doctest files. You can create your doctest files, similar to example given in README.txt:

ticketcollector

:doctest:
:functional-zcml-layer: ftesting.zcml

Open browser and test::

  >>> from zope.testbrowser.testing import Browser
  >>> browser = Browser()
  >>> browser.open('http://localhost/@@index')
  >>> 'Welcome to BlueBream' in browser.contents
  True

The fouth line specifies that a ZCML file named ftesting.zcml is required to setup the test layer.

To run the tests:

$ ./bin/test
blog comments powered by Disqus

Table Of Contents

Previous topic

9.9. Startup

Next topic

9.11. Skinning

This Page