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

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

Update documentation.

File size: 7.3 KB
Line 
1.. _testing:
2
3Testing
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.
18
19Why *automated* testing? Simply because no developer likes to click
20around the user interface to check tons of functionality. In Kofa
21more than 1300 tests, with dozens of actions per test, are being
22executed each time when the testrunner is started. This job can't be
23done manually.
24
25What we test: "Unit" and "Functional" Tests
26-------------------------------------------
27
28There are two different ways to test the code of a web application
29automatically: *unit tests* and *functional tests*. The goal of unit
30testing is to isolate each part of the program and show that the
31individual parts are correct. Functional tests of a web application
32are more wholistic, they require a running web application in the
33background with even a working (temporary) database. Functional
34tests are typically linked to a particular use case, they are
35interacting with the portal as a user would. That implies that
36functional testing has to make use of a test browser. A test browser
37does the same job as normal web browser does, except for visualizing
38the rendered HTML code.
39
40
41How we test: "Python" and "Doctest" Tests
42-----------------------------------------
43
44There are also two different ways to integrate tests, either
45functional or unit, into a Python package: *Doctest tests* (or doctests)
46and *Python tests*. Python test modules are a collection of
47isolatable Python test cases. A test case combines a collection of
48test methods which are being executed by the testrunner one
49after the other. Python test modules are automatically identified by
50means of their filenames which start with ``test_``. In contrast,
51doctests can be wrapped up in simple text files (ending with
52``.txt``), or they can be put into docstrings of the application's
53source code itself. Common to all doctests is that they are based on
54output from the standard Python interpreter shell (indicated by the
55interpreter prompt ``>>>``. The doctest runner parses all ``py`` and
56``txt`` files in our package, executes the interpreter commands
57found and compares the output against an expected value. Example::
58
59  Python's `math` module can compute the square root of 2:
60
61  >>> from math import sqrt
62  >>> sqrt(2)
63  1.4142135623730951
64
65Why wrapping tests into documentation? An objective of testdriven
66software development is also the documentation of the 'Application
67Programming Interface' (API) and, to a certain extent, providing a
68guideline to users, how to operate the portal. The first is mainly
69done in the docstrings of Python modules which present an expressive
70documentation of the main use cases of a module and its components.
71The latter is primarily done in separate ``txt`` files.
72
73When starting the development of Kofa, we relied on writing a
74coherent documentation including doctests in restructured text
75format. During the software development process, the focus shifted
76from doctesting to pure Python testing with a lot of functional
77tests inside. It turned out that Python tests are easier to handle
78and more powerful. Drawback is, that these tests cannot easily be
79integrated into the Sphinx documentation project (the documentation
80which you are reading right now). However, we will list some of
81these tests and try to explain what they are good for.
82
83
84Doctest Tests
85=============
86
87Browsing
88--------
89
90.. toctree::
91   :maxdepth: 2
92
93   testing/pages
94   testing/breadcrumbs
95
96Cataloging
97----------
98
99.. toctree::
100   :maxdepth: 2
101
102   testing/catalog
103
104Data Center
105-----------
106
107.. toctree::
108   :maxdepth: 2
109
110   testing/datacenter
111
112Security
113--------
114
115.. toctree::
116   :maxdepth: 2
117
118   testing/permissions
119
120Officers
121--------
122
123.. toctree::
124   :maxdepth: 2
125
126   testing/userscontainer
127
128University
129----------
130
131.. toctree::
132   :maxdepth: 2
133
134   testing/app
135
136Academic Section
137----------------
138
139.. toctree::
140   :maxdepth: 2
141
142   testing/certcourse
143
144Batch Processing
145----------------
146
147.. toctree::
148   :maxdepth: 2
149
150   testing/batchprocessing
151   testing/batchprocessing_browser
152
153Access Codes
154------------
155
156.. toctree::
157   :maxdepth: 2
158
159   testing/accesscode
160
161
162Python Tests
163============
164
165There are hundreds of Python test cases in Kofa with many test
166methods each. Here we present only a few of them. The test methods
167are easy to read. In most cases they are functional and certain
168methods and properties of a test browser are called. Most important
169are `browser.open()` (opens a web page), `browser.getControl()`
170(gets a control button), `browser.getLink()` (gets a link) and
171`browser.contents` (is the HTML content of the opened page).
172
173
174.. _test_suspended_officer:
175
176Suspended Officer Account
177-------------------------
178
179The first test can be found in
180`waeup.kofa.browser.tests.test_browser.SupplementaryBrowserTests`.
181The test makes sure that suspended officers can't login but see a
182proper warning message when trying to login. Furthermore, suspended
183officer accounts are clearly marked and a warning message shows up
184if a manager accesses a suspended account, see :ref:`Officers
185<officers>`.
186
187.. literalinclude:: ../../../src/waeup/kofa/browser/tests/test_browser.py
188   :pyobject: SupplementaryBrowserTests.test_suspended_officer
189
190
191.. _test_handle_clearance:
192
193Handling Clearance by Clearance Officer
194---------------------------------------
195
196This test can be found in
197`waeup.kofa.students.tests.test_browser.OfficerUITests`. The corresponding use
198case is partly described :ref:`elsewhere <rejecting_clearance>`.
199
200.. literalinclude:: ../../../src/waeup/kofa/students/tests/test_browser.py
201   :pyobject: OfficerUITests.test_handle_clearance_by_co
202
203
204.. _test_handle_courses:
205
206Handling Course List Validation by Course Adviser
207-------------------------------------------------
208
209This test can be found in
210`waeup.kofa.students.tests.test_browser.OfficerUITests`. The corresponding use
211case is described :ref:`elsewhere <course_registration>`.
212
213.. literalinclude:: ../../../src/waeup/kofa/students/tests/test_browser.py
214   :pyobject: OfficerUITests.test_handle_courses_by_ca
215
216
217.. _test_batch_editing_scores:
218
219Batch Editing Scores by Lecturers
220---------------------------------
221
222These test can be found in
223`waeup.kofa.students.tests.test_browser.LecturerUITests`. The corresponding use
224cases are described :ref:`elsewhere <batch_editing_scores>`.
225
226.. literalinclude:: ../../../src/waeup/kofa/students/tests/test_browser.py
227   :pyobject: LecturerUITests
228
229.. _test_manage_hostels:
230
231Manage Hostel
232-------------
233
234This test can be found in
235`waeup.kofa.hostels.tests.HostelsUITests`. The corresponding use
236case is described :ref:`elsewhere <hostels_pages>`.
237
238.. literalinclude:: ../../../src/waeup/kofa/hostels/tests.py
239   :pyobject: HostelsUITests.test_add_search_edit_delete_manage_hostels
240
241.. _test_handle_accommodation:
242
243Bed Space Booking
244-----------------
245
246This test can be found in
247`waeup.kofa.students.tests.test_browser.StudentUITests`. The corresponding use
248case is described :ref:`elsewhere <bed_tickets>`.
249
250.. literalinclude:: ../../../src/waeup/kofa/students/tests/test_browser.py
251   :pyobject: StudentUITests.test_student_accommodation
Note: See TracBrowser for help on using the repository browser.