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