ZopeGuideFunctionalTesting

Functional testing

Introduction

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

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'

Running tests

By conventions your functional test modules are put in ftests packages under each main packages. But the doctest files can be placed in the package itself. Create a sub-package zopetic.ftests, under this package create test modules like test_main.py, test_extra.py etc.

To run the functional tests, change to instance home:

$ cd $HOME/myzope/etc
$ ../bin/test -vpf --dir zopetic

Note that, for unit test 'vpu' is used and here it is 'vpf'.



( 101 subscribers )