Ignore:
Timestamp:
11 May 2015, 13:35:06 (10 years ago)
Author:
Henrik Bettermann
Message:

Introduction to testing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/docs/source/userdocs/testing.rst

    r12921 r12924  
    44**************************
    55
    6 DocTests
     6Kofa's Python code is being tested automaticallyy. The developers'
     7goal is to reach 100% code coverage by Kofa's test runners, which
     8means that each single line of code is passed at least one time when
     9running the tests.
     10
     11Why testing? Testing makes sure that our code works properly under
     12given sets of conditions and, only comprehensive testing ensures
     13that changing or customizing the code does not break existing
     14functionality. Why *automated* testing? Simply because no developer
     15likes to click around the user interface to check tons of
     16functionality. In Kofa more than 1100 tests, with dozens of actions
     17per test, are being executed each time when the testrunner is
     18started. This job can't be done manually.
     19
     20There are two different ways to test the code of a web application
     21automatically: *unit tests* and *functional tests*. The goal of unit
     22testing is to isolate each part of the program and show that the
     23individual parts are correct. Functional tests of a web application
     24are more wholistic, they require a running web application in the
     25background with even a working (temporary) database. Functional
     26tests are typically linked to a particular use case, they are
     27interacting with the portal as a user would. That implies that
     28functional testing has to make use of a test browser. A test browser
     29does the same job as normal web browser do, except for visualizing
     30the rendered html code.
     31
     32There are also two different ways to integrate tests, either
     33functional or unit, into a Python package: *doc tests* (or doctests)
     34and *Python tests*. Python test modules are a collection of
     35isolatable Python test cases. A test case combines a collection of
     36unit test methods which are being executed by the testrunner one
     37after the other. Python test modules are automatically identified by
     38means of their filenames which start with ``test_``. In contrast,
     39doctests can be wrapped up in simple text files (ending with
     40``.txt``), or they can be put into docstrings of the application's
     41source code itself. Common to all doctests is that they are based on
     42output from the standard Python interpreter shell (indicated by the
     43interpreter prompt ``>>>``. The doctest runner parses all ``py`` and
     44``txt`` files in our package, executes the interpreter commands
     45found and compares the output against an expected value. Example::
     46
     47  Python's `math` module can compute the square root of 2:
     48
     49  >>> from math import sqrt
     50  >>> sqrt(2)
     51  1.4142135623730951
     52
     53Why wrapping tests into documentation? An objective of testdriven
     54software development is also the documentation of the 'Application
     55Programming Interface' (API) and, to a certain extent, providing a
     56guideline to users, how to operate the portal. The first is mainly
     57done in the docstrings of Python modules which present an expressive
     58documentation of the main use cases of a module and its components.
     59The latter is primarily done in separate ``txt`` files.
     60
     61When starting the development of Kofa, we relied on writing a
     62coherent documentation including doctests in restructured text
     63format. During the software development process the focus shifted
     64from doctesting to pure Python testing with a lot of functional
     65tests inside. It turned out that Python tests are easier to handle
     66and more powerful. Drawback is, that these tests cannot easily be
     67integrated into the Sphinx documentation project (the documentation
     68which you are reading right now). However, we will list some of
     69these tests and try to explain what they are good for.
     70
     71
     72Doctests
    773========
    874
     
    74140
    75141
    76 Python Tests
    77 ============
     142Pythontests
     143===========
Note: See TracChangeset for help on using the changeset viewer.