source: tags/arb-6.0/UNIT_TESTER/README.txt

Last change on this file was 11888, checked in by westram, 10 years ago
  • highlight differences in production code triggered by build-flag 'UNIT_TESTS'
File size: 6.3 KB
Line 
1
2How to use ARB unit testing
3---------------------------
4
51. Invocation
6
7   Edit config.makefile. Set UNIT_TESTS to 1
8
9   cd $ARBHOME
10   make unit_tests
11
12   'make all' runs tests as well ('make build' doesn't)
13
142. Add unit test code
15
16   Go to the unit containing your_function() and add something like
17   the following to the end of the file.
18
19       #if (UNIT_TESTS == 1)
20
21       #include <test_unit.h>
22
23       void TEST_your_function() {
24       }
25
26       #endif
27
28   The names of the test functions are important:
29       - they have to start with 'TEST_' and
30       - need to be visible at global scope.
31
32   (see also 'Building tests' at end of file)
33
34
35   Test result:
36
37      If TEST_your_function() does nothing special, it is assumed the unit test passed "ok".
38
39      If your function fails an assertion (TEST_ASSERT) or raises SIGSEGV in any other manner,
40      it is assumed the unit test failed and an error message is printed to the console.
41
42      (Any other test function in the same unit will nevertheless get called.)
43
44
45   Post conditions:
46
47      If a unit defines one or more tests called
48         void TEST_POSTCOND_xxx()
49      each of these post condition tests will be run after EACH single unit test.
50
51      These post condition tests are intended to check for unwanted global side-effects of
52      test-functions. Such side effects often let other (unrelated) test-functions fail
53      unexpectedly. Use them to undo these side-effects.
54
55      If the post-condition fails, the test itself will be reported as failure.
56
57      If the test itself has failed for other reasons, post condition tests will nevertheless
58      be executed (and may do their cleanups), but their failures will not be shown in the log.
59
60
61   Failing tests:
62
63      If you have some broken behavior that you cannot fix now, please do NOT leave
64      the test as "failing". Instead change TEST_ASSERT into
65
66          TEST_ASSERT_BROKEN(failing_condition);
67
68      That will print a warning as reminder as long as the condition fails.
69      When the behavior was fixed (so that the condition is fulfilled now),
70      it will abort the test as failed!
71      Just change TEST_ASSERT_BROKEN back into TEST_ASSERT then.
72
73      Set WARN_LEVEL to 0 in Makefile.setup.local to disable warnings.
74
75
76   Missing tests:
77
78      You may drop a reminder like
79
80          MISSING_TEST(describe what is missing);
81
82      which will appear as warning during test run.
83
84
85   Order of tests:
86
87      Tests are executed in the order they appear in the code.
88      Multiple Files are sorted alphabethically.
89
90      Exceptions:
91      - If test name starts with 'TEST_###' (where ### are digits), it declares a test with priority ###.
92        The default priority is 100. Lower numbers mean higher priority, i.e. start more early.
93      - Other predefined priorities are
94        - TEST_BASIC_       (=20)
95        - TEST_EARLY_       (=50)
96        - TEST_             (=100 default)
97        - TEST_LATE_        (=200)
98        - TEST_SLOW_        (=900)
99        - TEST_AFTER_SLOW_  (=910)
100
101        TEST_SLOW_... is meant to indicate "slow" tests (i.e. tests which need more than
102        a second to execute).
103
104   Order of test units:
105
106      Tests from each unit (aka library) run consecutive.
107      Tests of different units are executed asynchronously.
108
109   Code differences when compiled with UNIT_TESTS=1
110
111      Some unit tests require differences in production code, e.g.
112      - to inspect class internals
113      - to provoke special conditions (e.g. reduce some buffer size to simulate big
114        amount of processed data)
115
116      Such differences should be marked with a comment containing 'UT_DIFF'.
117
118
1193. Valgrinding test code
120
121   If you set
122
123      VALGRIND=A
124
125   in UNIT_TESTER/Makefile.setup.local, valgrind will be started on the test-binary after the normal
126   unit tests passed with success.
127   Valgrind errors/warnings will not raise an error or abort testing.
128
129
130   If you set
131
132      VALGRIND=B
133
134   valgrind will be started BEFORE running tests.
135   Useful if test fail unexpectedly and you suspect a memory bug.
136
137   See also ENABLE_CRASH_TESTS in test_unit.h (all crash tests are reported by valgrind)
138
139
140   If you set
141
142      VALGRIND=E
143
144   some external tools like arb_pt_server will be spawned valgrinded and the generated
145   reports will be printed on test termination.
146
147   Any combination of the above works as well.
148
1494. Check test-coverage
150
151   set 'COVERAGE=1' in config.makefile and 'make rebuild'
152
153   - prints out uncovered code to compile log
154   - leaves info for partly covered code files in yourcode.cxx.cov
155
156   Note:
157        You can silence lines which are never reached while testing
158        with a comment containing 'NEED_NO_COV'.
159
160   call 'make clean_coverage_results' to get rid of .cov files
161
162   (see also showCoverageForAll in gcov2msg.pl)
163
1645. Running only some tests
165
166   Set 'RESTRICT=expr' to '.' to run all tests.
167
168   Set it to sth else to run only tests for matching source files.
169   This is helpful if you'd like to check test-coverage.
170
171   Set 'RESTRICT_LIB=lib1:lib2' to test only a few libs.
172
173
174   Slow tests ('TEST_SLOW_...'; see above) will only run every 15 minutes.
175
176
1776. Global test environments
178
179   Environments provide a test situation which takes some reasonable time
180   for startup.
181
182   Multiple tests will be permitted to use one environment, but they will
183   be serialized (even if tests are running in multiple processes).
184
185   These environments have to be coded directly in TestEnvironment.cxx
186   (for existing environments see TestEnvironment.cxx@ExistingEnvironments)
187
188   If you write a test that wishes to use one of the environments simply write
189      TEST_SETUP_GLOBAL_ENVIRONMENT("name"); // starts environment 'name'
190
191
1927. Auto-patch generation
193
194   Whenever unit tests complete successfully, a patch (svn diff) is generated and
195   stored inside $ARBHOME/patches.arb/
196
197   After PATCHES_KEEP_HOURS seconds the patch will be deleted automatically
198   (see Makefile.setup.local), considering at least PATCHES_MIN_KEPT patches remain.
199
2008. Building tests
201
202   To build and execute a test-executable for a previously untested subdir
203   the following steps are necessary:
204
205   - add the test to the list of performed tests in ../Makefile@UNITS_TESTED
206   - if the test subject is a shared library, be sure to mention it a Makefile.test@SHAREDLIBS
207   - if the test subject is an executable, be sure to mention it a Makefile.test@EXEOBJDIRS
Note: See TracBrowser for help on using the repository browser.