IMP logo
IMP Manual  for IMP version 2.16.0
testing.md
1 Debugging and testing your code {#testing}
2 ===============================
3 
4 Ensuring that your code is correct can be very difficult, so %IMP
5 provides a number of tools to help you out.
6 
7 The first set are assert-style macros to use in the C++ code:
8 
9 - IMP_USAGE_CHECK() which should be used to check that arguments to
10  functions and methods satisfy the preconditions.
11 
12 - IMP_INTERNAL_CHECK() which should be used to verify internal state
13  and return values to make sure they satisfy pre and post-conditions.
14 
15 See the [checks](../ref/exception_8h.html) page for more details. As a
16 general guideline, any improper usage should produce at least a warning
17 and all return values should be checked by such code.
18 
19 The second is logging macros such as:
20 
21 - IMP_LOG() which allows controlled display of messages about what the
22  code is doing. See [logging](../ref/log_8h.html) for more information.
23 
24 Finally, each module has a set of unit tests. The
25 tests are located in the `modules/modulename/test` directory.
26 These tests should try, as much as possible, to provide independent
27 verification of the correctness of the code. Any
28 file in that directory or a subdirectory whose name matches `test_*.{py,cpp}`,
29 `medium_test_*.{py,cpp}` or `expensive_test_*.{py,cpp}` is considered a test.
30 Normal tests should run in at most a few seconds on a typical machine, medium
31 tests in 10 seconds or so and expensive tests in a couple of minutes.
32 
33 Python tests can, in principle, be any Python script that exits without error
34 if the test passes. However, in most cases it makes sense to use the Python
35 [unittest framework](https://docs.python.org/2/library/unittest.html). We
36 provide a custom test case subclass that provides some useful IMP-specific
37 functions (IMP::test::TestCase). The convention in %IMP is for tests to
38 make a subclass of this class called `Tests` (this makes it easier to run
39 individual tests from the command line). Some tests will require input files
40 or temporary files. Input files
41 should be placed in a directory called `input` in the `test`
42 directory. The test script should then call
43 \command{self.get_input_file_name(file_name)} to get the true path to
44 the file. Likewise, appropriate names for temporary files should be
45 found by calling
46 \command{self.get_tmp_file_name(file_name)}.
#define IMP_USAGE_CHECK(expr, message)