Changes between Initial Version and Version 1 of Self_Test_Helpers


Ignore:
Timestamp:
Feb 23, 2008, 4:18:59 AM (16 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Self_Test_Helpers

    v1 v1  
     1[KEEP IN SYNC WITH SELF_TEST.H!]
     2
     3== Introduction ==
     4
     5Self-tests as advocated by eXtreme Programming have proven to be useful.
     6By embedding test code into modules, we can be confident that boundary cases are handled correctly and everything still works after edits. We give guidelines for their use and explain several helper mechanisms below.
     7
     8
     9== Guidelines ==
     10
     11What makes a good self-test?
     12 * They belong in the module being tested to ensure they are kept in sync with it.
     13 * It is easiest to attach them to low-level functions, e.g. ilog2, rather than verifying the module's final result (e.g. checking renderer output by comparing pictures).
     14 * You should cover all cases: expected failures ("does it fail as expected?"), bad inputs ("does it reject those?"), and successes ("did it have the expected result?").
     15 * Tests should be non-intrusive (only bother user if something fails) and very quick. This is because we run them automatically at startup, which solves the common problem of making sure they actually run. [[BR]]If the test must by definition be slow or annoying (example: wdbg_sym's stack trace), then best to disable it by default (see below for how). It can then be enabled manually after changes, and that is better than no test at all.
     16
     17
     18== Example Usage ==
     19
     20The following is a working example of a built-in self test using
     21our facilities. Further notes below are referenced with (1) etc.
     22
     23 
     24{{{
     25 #if SELF_TEST_ENABLED                          // (1)
     26 namespace test {                               // (2)
     27 
     28 static void test_log2()
     29 {
     30        TEST(ilog2(0) == -1);                   // (3)
     31        // further test cases..
     32 }
     33 
     34 static void self_test()
     35 {
     36        test_log2();
     37        // further test groups..
     38 }
     39 
     40 RUN_SELF_TEST;                                 // (4)
     41 
     42 }      // namespace test
     43 #endif // #if SELF_TEST_ENABLED
     44}}}
     45
     46 1. when not enabled, self-tests are completely removed so as not to bloat the executable. for details on how to enable/disable them globally or override in single files, see self_test.h.
     47
     48 1. wrapping in a namespace is optional and must be removed for C programs. it avoids possible name collisions with the module being tested.
     49
     50 1. TEST *must* be used instead of debug_assert et al.! this is explained below.
     51
     52 1. automatically calls your self_test function at non-local static object init time (i.e. before main is entered).
     53
     54For further details, see self_test.h.