source: main/waeup.kofa/trunk/docs/source/userdocs/testing.rst @ 12951

Last change on this file since 12951 was 12951, checked in by Henrik Bettermann, 10 years ago

Simplify headlines in doctests. Remove some API documentation.

File size: 5.7 KB
Line 
1.. _testing:
2
3Testing :sup:`in progress`
4**************************
5
6Introduction
7============
8
9Kofa's Python code is being tested automatically. The developers'
10goal is to reach 100% code coverage by Kofa's test runners, which
11means that each single line of code is passed at least one time when
12running the tests.
13
14Why testing? Testing makes sure that our code works properly under
15given sets of conditions and, only comprehensive testing ensures
16that changing or customizing the code does not break existing
17functionality. Why *automated* testing? Simply because no developer
18likes to click around the user interface to check tons of
19functionality. In Kofa more than 1300 tests, with dozens of actions
20per test, are being executed each time when the testrunner is
21started. This job can't be done manually.
22
23Why *automated* testing? Simply because no developer likes to click
24around the user interface to check tons of functionality. In Kofa more
25than 1100 tests, with dozens of actions per test, are being executed
26each time when the testrunner is started. This job can't be done
27manually.
28
29What we test: "Unit" and "Functional" Tests
30-------------------------------------------
31
32There are two different ways to test the code of a web application
33automatically: *unit tests* and *functional tests*. The goal of unit
34testing is to isolate each part of the program and show that the
35individual parts are correct. Functional tests of a web application
36are more wholistic, they require a running web application in the
37background with even a working (temporary) database. Functional
38tests are typically linked to a particular use case, they are
39interacting with the portal as a user would. That implies that
40functional testing has to make use of a test browser. A test browser
41does the same job as normal web browser does, except for visualizing
42the rendered HTML code.
43
44
45How we test: "Python" and "Doctest" Tests
46-----------------------------------------
47
48There are also two different ways to integrate tests, either
49functional or unit, into a Python package: *Doctest tests* (or doctests)
50and *Python tests*. Python test modules are a collection of
51isolatable Python test cases. A test case combines a collection of
52test methods which are being executed by the testrunner one
53after the other. Python test modules are automatically identified by
54means of their filenames which start with ``test_``. In contrast,
55doctests can be wrapped up in simple text files (ending with
56``.txt``), or they can be put into docstrings of the application's
57source code itself. Common to all doctests is that they are based on
58output from the standard Python interpreter shell (indicated by the
59interpreter prompt ``>>>``. The doctest runner parses all ``py`` and
60``txt`` files in our package, executes the interpreter commands
61found and compares the output against an expected value. Example::
62
63  Python's `math` module can compute the square root of 2:
64
65  >>> from math import sqrt
66  >>> sqrt(2)
67  1.4142135623730951
68
69Why wrapping tests into documentation? An objective of testdriven
70software development is also the documentation of the 'Application
71Programming Interface' (API) and, to a certain extent, providing a
72guideline to users, how to operate the portal. The first is mainly
73done in the docstrings of Python modules which present an expressive
74documentation of the main use cases of a module and its components.
75The latter is primarily done in separate ``txt`` files.
76
77When starting the development of Kofa, we relied on writing a
78coherent documentation including doctests in restructured text
79format. During the software development process the focus shifted
80from doctesting to pure Python testing with a lot of functional
81tests inside. It turned out that Python tests are easier to handle
82and more powerful. Drawback is, that these tests cannot easily be
83integrated into the Sphinx documentation project (the documentation
84which you are reading right now). However, we will list some of
85these tests and try to explain what they are good for.
86
87
88Doctest Tests
89=============
90
91Browsing
92--------
93
94.. toctree::
95   :maxdepth: 2
96
97   testing/browser
98   testing/breadcrumbs
99
100Cataloging
101----------
102
103.. toctree::
104   :maxdepth: 2
105
106   testing/catalog
107
108Data Center
109-----------
110
111.. toctree::
112   :maxdepth: 2
113
114   testing/datacenter
115
116Security
117--------
118
119.. toctree::
120   :maxdepth: 2
121
122   testing/permissions
123
124Officers
125--------
126
127.. toctree::
128   :maxdepth: 2
129
130   testing/userscontainer
131
132University
133----------
134
135.. toctree::
136   :maxdepth: 2
137
138   testing/app
139
140Academic Section
141----------------
142
143.. toctree::
144   :maxdepth: 2
145
146   testing/certcourse
147
148Batch Processing
149----------------
150
151.. toctree::
152   :maxdepth: 2
153
154   testing/batchprocessing
155   testing/batchprocessing_browser
156
157Access Codes
158------------
159
160.. toctree::
161   :maxdepth: 2
162
163   testing/accesscode
164
165
166Python Tests
167============
168
169There are hundreds of Python test cases in Kofa with many test
170methods each. Here we present only a few of them. The test methods
171are easy to read. In most cases they are functional and certain
172methods and properties of a test browser are called. Most important
173are `browser.open()` (opens a web page), `browser.getControl()`
174(gets a control button), `browser.getLink()` (gets a link) and
175`browser.contents` (is the HTML content of the opened page).
176
177.. _test_suspended_officer:
178
179Suspended Officer Account
180-------------------------
181
182The first test can be found in
183`waeup.kofa.browser.tests.test_browser.SupplementaryBrowserTests`:
184
185.. literalinclude:: ../../../src/waeup/kofa/browser/tests/test_browser.py
186   :pyobject: test_suspended_officer
187
188The test makes sure that a suspended officers can't login but see a
189proper warning message when trying to login. Furthermore, suspended
190officer accounts are clearly marked and a warning message shows up
191if a manager accesses a suspended account, see :ref:`Officers
192<officers>`.
Note: See TracBrowser for help on using the repository browser.