Killrazor Killrazor - 1 year ago 179
C++ Question

How to catch an assert with Google test?

I'm programming some unit test with the Google test framework. But I want to check whether some asserts are well placed and are useful. Is there a way to catch an assert in Google test?

Example code under test:

int factorial(int n){
assert(n >= 0);

And then the test:

#include <gtest/gtest.h>

doesn't catch the assert but only exceptions. I'm searching for a solution to catch asserts.

Answer Source

Google test provides ASSERT_DEATH, EXPECT_DEATH and other related macros.

This question and What are Google Test, Death Tests are each other's answers. Does that make them duplicates, or not? ;-)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download