~launchpad-results/launchpad-results/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Testing
=======

When developing for the Launchpad Results project, you should run the
test suite on a regular basis.

Running all tests
-----------------

The simplest way to run all tests is to call the test command from the
project's manage.py utility::

    bin/manage.py test

This uses the test runner from the ``zope.testrunner`` module which
provides many command line options as can be seen from the help::

    bin/manage.py test --help


Running in parallel
-------------------

The above command can take a while to run which is not good for test
driven development. Instead, you can experiment with the "-j" option
which defines the number of parallel processes to run tests. The default
value is only 1 whereas a good value to try is the number of cores
on your system. For example, this would be the command to try with 2
cores::

    bin/manage.py test -j 2


Filtering tests
---------------

If you are working on a single module, you can filter the tests instead of
running all of them. The "-t" option specifies a case-sensitive regular
expression to limit which test classes are searched for tests. For
example, this command would run the tests defined in class TestFoo::

    bin/manage.py test -t TestFoo

The "-m" option also specifies a case-sensitive regular expression, but
to limit test modules instead of classes. This is useful when multiple
test classes are defined in the same module which can all be run with
this command::

    bin/manage.py test -m test_foo

The test runner provides more filtering options as can be seen from
the help.


Iterating tests
---------------

If you are working across many modules, you can iterate over your
changes quickly by limiting tests to only those that failed the previous
run. This first requires initializing the project with ``testrepository``
and running the testr command to record all failures::

    sudo apt-get install testrepository
    testr init
    testr run

The "--failing" option can subsequently be used to run only tests known
to be failing::

    testr run --failing

This command can be run repeatedly until there are no more failing
tests. Once finished, the .testrepository directory where all test runs
were recorded can be safely removed.