CoolSteve
CoolSteve

Reputation: 271

In google test can a test be marked as skipped instead of failed, during test execution

In google test is there a way of marking a test as SKIPPED if an assertion fails?

e.g. ASSERT_TRUE(1 != 1)

So if the above statement fails, can I add something to gtest to mark the test as skipped instead of failed?

Upvotes: 3

Views: 9323

Answers (2)

J. Bakker
J. Bakker

Reputation: 356

GTEST_SKIP can be used to mark a test during execution.

For example:

TEST(SkipTest, DoesSkip) {
  GTEST_SKIP() << "Skipping single test";
  EXPECT_EQ(0, 1);  // Won't fail; it won't be executed
}

Upvotes: 2

Fraser
Fraser

Reputation: 78418

Not that I know of. Probably for good reason, since it looks kinda cheaty to "skip" a test only once you hit a failure! If you know a test will fail before running it, then you can disable it temporarily by prepending DISABLED_ to the test name.

This seems like a better option since the test code still gets compiled, but the suite's overall result is unaffected since the test is not run. The output nags you by reminding you how many disabled tests you have, and you can always force the disabled test to run if required using the --gtest_also_run_disabled_tests arg.

By the way, gtest provides ways to explicitly cause your test to fail rather than doing ASSERT_TRUE(1 != 1).

Upvotes: 13

Related Questions