the Compartmented Robust Posix C++ Unit Test system | hosted by |
---|
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() { buffer.at(1) = 0; /* init */ } char &next_char() { return buffer[index++]; } int used_chars() const { return index; } private: std::vector<char> buffer; int 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(), 100); } int main(int argc, char *argv[]) { return crpcut::run(argc, argv); }
Running this test program yields:
FAILED: create phase="running" -------------------------------------------------------------- Unexpectedly caught std::exception what()=vector::_M_range_check ------------------------------------------------------------------------------- =============================================================================== The following tests were blocked from running: destroy fill Total 3 test cases selected UNTESTED : 2 PASSED : 0 FAILED : 1
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(...)
.