2

I have a lot of C++ test-cases that are all implemented using the CppUnit unit testing framework.

In our project we have tons of statements in various test-classes and various helper classes - short - spread around the whole testing code - which all somewhere deep inside rely on the various CPPUNIT_ASSERT_**** macros to ensure the results are as expected.

A typical helper function that is used during the testing framework might look like this:

void checkMatricesEqual(const Matrix& ref,const Matrix& val) {
    CPPUNIT_ASSERT_EQUAL(ref.w,val.w);
    CPPUNIT_ASSERT_EQUAL(ref.h,val.h);
    ...
    ...
}

Now, if an assertion fails, CppUnit prints out the name of the test function, and the file.cpp:line, which is not very helpful if it points to a general test helper function like the one above. In a big testing framework the location of an error can be hard to track down then.

Instead, I would really love to see a stack trace as output instead. I know that printing a stack trace from with some chunk of code using internal gcc libraries and -g is possible How to generate a stacktrace when my gcc C++ app crashes.

What I don't know: How can one integrate this with CppUnit? Create a patch and override the original CppUnit functionality? Maybe somehow hook into the generation of messages?

If anyone has a hint how to accomplish something like this I would really appreciate.

Community
  • 1
  • 1

0 Answers0