Reputation: 2861
I'm trying to figure out how to do TearDown() in the face of ASSERT failures in Google Test.
A dummy example is below:
class TestFixture: public testing::Test
{
protected:
virtual void SetUp()
{
// Do per test setup
}
virtual void TearDown()
{
// Do per test teardown
}
}
TEST_F(TestFixture, MyTest)
{
ASSERT_TRUE(false);
}
What I'm trying to acheive is for TearDown() to be called even if the test throws an assertion failure. GoogleTest doesn't call TearDown() when an assertion is thrown. How do I go about this?
Upvotes: 0
Views: 3178
Reputation: 163287
Put your setup code in the fixture's constructor, and put your tear-down code in the destructor.
Upvotes: 2