Is there a way to check that SetUp code has actually worked properly in GTest fixtures, so that the whole fixture or test-application can be marked as failed rather than get weird test results and/or have to explicitly check this in each test?
Can you test SetUp success/failure in Google Test
googletest
Best Answer
If you put your fixture setup code into a
SetUp
method, and it fails and issues a fatal failure (ASSERT_XXX
orFAIL
macros), Google Test will not run your test body. So all you have to write isThen
MyTestCase.Foo
will not execute ifInitMyTestData()
returns false. If you already have nonfatal assertions in your setup code (i.e.,EXPECT_XXX
orADD_FAILURE
), you can generate a fatal assertion from them by writingASSERT_FALSE(HasFailure());
You can find more info on failure detection in the Google Test Advanced Guide wiki page.