Separate Test Files

Placing tests in separate files often helps debug problems related to file inclusion, etc., in C/C++:

E.g. a package consists of file foo.h and foo.c

The test foo-test.cc looks like

    #include "foo.h"
    #include "foo.h"

class test_foo { public: void test() { ... } };

Not only does this reduce the amount of code in one place by separating the test aspect from the code, but it also tests that the header can be multiply included.


Actually, testing that the header is freestanding and can be multiply included, done by

    #include "foo.h"
    #include "foo.h"
    int main() {}
is important enough that it should be left to a separate tool.


EditText of this page (last edited November 6, 2002) or FindPage with title or text search