the Compartmented Robust Posix C++ Unit Test system |
|
---|
With crpcut you can express dependencies between tests, so that a test that builds on a fundamental functionality, can state a dependency on a test that covers the basics. If a bug is found in the basic test, the more advanced tests won't even run. This reduces clutter in the test report, and help you focus on the important errors.
Dependencies are expressed using the
DEPENDS_ON(...)
test modifier.
It is used as in the below program:
#include <crpcut.hpp> #include <vector> class to_be_tested { public: to_be_tested() : index(0) { buffer.at(1) = 0; /* init */ } char &next_char() { return buffer[index++]; } size_t used_chars() const { return index; } private: std::vector<char> buffer; size_t index; }; TEST(create) { (void)new to_be_tested; // intentional leak } TEST(destroy, DEPENDS_ON(create)) { to_be_tested obj; } TEST(fill, DEPENDS_ON(destroy)) { to_be_tested obj; for (int i = 0; i < 100; ++i) { obj.next_char() = 0; } ASSERT_EQ(obj.used_chars(), 100U); } int main(int argc, char *argv[]) { return crpcut::run(argc, argv); }
Running this test program yields:
FAILED!: create phase="running" -------------------------------------------------------------- samples/simple-depend.cpp:40 Unexpectedly caught std::exception what()=vector::_M_range_check: __n (which is 1) >= this->size() (which is 0) ------------------------------------------------------------------------------- =============================================================================== The following tests were blocked from running: !destroy !fill 3 test cases selected Sum Critical Non-critical FAILED : 1 1 0 UNTESTED : 2
Instead of each test failing for the same reason, a clean test report is shown with full reports from the test(s) that failed, and a list of the names of the tests that were blocked from running.
The DEPENDS_ON(...)
modifier can only be used once for each test, but it accepts many
parameters. Just add as many tests as are necessary in the parameter
list of DEPENDS_ON(...)
.
Note | |
---|---|
If you use GCC version 4.3 or higher, and compile your test sources with -std=c++0x, there is no limit to the number of parameters, otherwise you can list maximum 17 tests or testsuites in the parameter list. |