views:

36

answers:

1

Hello, I'm programming some unit test with google test framework. But I want to check is some asserts are well placed and are useful. So my question is: does exists a way to catch an assert in google test?

Example:

int factorial(int n){
    assert(n >= 0);
    //....
}

And then the test:

#include <gtest/gtest.h>
TEST(FactorialTest,assertNegative){
    EXPECT_ANY_THROW({
         factorial(-1);
    });
}

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

Thanks to all

+2  A: 

http://code.google.com/p/googletest/wiki/AdvancedGuide#Death_Tests.

This question and http://stackoverflow.com/questions/3698718/what-are-google-test-death-tests are each other's answers. Does that make them duplicates, or not? ;-)

Steve Jessop
Thanks. Its all I need. How do I close the question, then?
Killrazor
@Killrazor: If you think it is a dupe, then to close a question you get 5 people, each with sufficient rep to have that permission, to vote to close it. But I wouldn't worry about it - this question will disappear quickly off the "recent", "active" and "hot" questions lists if it hasn't already, so it's not in anyone's way. It might be useful that it uses different terms and hence shows up in different Google searches.
Steve Jessop