We have a series of death tests that check that specific debug asserts
fire. For example, we construct something like this:
LockManager::LockManager(size_t numManagedLocks) :
_numManagedLocks(numManagedLocks)
{
assert(_numManagedLocks <= MAX_MANAGABLE_LOCKS &&
"Attempting to manage more than the max possible locks.");
And we have a test for its failure:
EXPECT_DEATH(LockManager sutLockManager(constants::MAX_NUMBER_LOCKS + 1),
"Attempting to manage more than the max possible locks.");
Since assert is only compiled in debug, these tests will fail when the component is built in release. Is the best way to avoid this to wrap EXPECT_DEATH
tests in a DEBUG
detection macro:
#ifndef NDEBUG
// DEATH TESTS
#endif
Or is there an approach that is better and specific to Google Test?
I think that GTest have a solution to this now: EXPECT_DEBUG_DEATH