I am currently using Boost.Log in one of my software projects. There is one case, where I report an error condition by using a log message. I would like to test whether this condition is detected correctly using google testing framework. Just to be clear, I want to test whether the message is generated. It may be removed by a filter, but this should not cause the test to fail. Is this possible at all? Any hints? Thanks!
Asked
Active
Viewed 104 times
1 Answers
1
For base yes-or-no testing, simply use assert
, something like this:
#include <assert.h> /* assert */
void print_number(int* myInt) {
assert (myInt!=NULL);
// Boost.Log stuff...
// print_number stuff...
}
this will give you a straight up message (depending on compiler/OS) if the test fails.

Paul Evans
- 27,315
- 3
- 37
- 54
-
The solution is not quite as general as I had hoped for (e.g. testing for warnings), but works for the case at hand. Thanks for setting me straight, I was so focused on the possibility of detecting that log message that I did not consider the obvious solution! I'll accept your answer later on in case no one shows up with a more general one. – Markus Mayr Nov 21 '13 at 10:30
-
You can also easily disable for production code with a simple `#define NDEBUG ` seen (i.e in your general header or in the makefile/command-line) before the `#include
` – Paul Evans Nov 21 '13 at 10:34