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

Last change on this file since 12942 was 12942, checked in by Henrik Bettermann, 9 years ago

Update links.

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
132Academic Section
133----------------
134
135.. toctree::
136   :maxdepth: 2
137
138   testing/certificate
139
140Batch Processing
141----------------
142
143.. toctree::
144   :maxdepth: 2
145
146   testing/batchprocessing_part1
147   testing/batchprocessing_part2
148
149Access Codes
150------------
151
152.. toctree::
153   :maxdepth: 2
154
155   testing/accesscode
156
157
158Python Tests
159============
160
161There are hundreds of Python test cases in Kofa with many test
162methods each. Here we present only a few of them. The test methods
163are easy to read. In most cases they are functional and certain
164methods and properties of a test browser are called. Most important
165are `browser.open()` (opens a web page), `browser.getControl()`
166(gets a control button), `browser.getLink()` (gets a link) and
167`browser.contents` (is the HTML content of the opened page).
168
169.. _test_suspended_officer:
170
171Suspended Officer Account
172-------------------------
173
174The first test can be found in
175`waeup.kofa.browser.tests.test_browser.SupplementaryBrowserTests`:
176
177.. literalinclude:: ../../../src/waeup/kofa/browser/tests/test_browser.py
178   :pyobject: test_suspended_officer
179
180The test makes sure that a suspended officers can't login but see a
181proper warning message when trying to login. Furthermore, suspended
182officer accounts are clearly marked and a warning message shows up
183if a manager accesses a suspended account, see :ref:`Officers
184<officers>`.
Note: See TracBrowser for help on using the repository browser.