From c4ed56eb75b1c1f9d1fc7e98f8c9724bb73e2442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=A4mer?= Date: Tue, 15 Dec 2020 21:24:41 +0100 Subject: [PATCH] Add subsection for GTEST_SKIP documentation A subsection "Skipping test execution" was added to document GTEST_SKIP and where it can be used. relates issue #1544 --- docs/advanced.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/advanced.md b/docs/advanced.md index ae4d7ee8..da7cf079 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -527,6 +527,32 @@ destructor early, possibly leaving your object in a partially-constructed or partially-destructed state! You almost certainly want to `abort` or use `SetUp`/`TearDown` instead. +## Skipping test execution + +Related to pseudo assertions `SUCCEED()` and `FAIL()` you can prevent further test +execution with the `GTEST_SKIP()` macro. + +`GTEST_SKIP` can be used in test cases or in `SetUp()` methods of classes inherited +from either `::testing::Environment` or `::testing::Test`. The latter is a convenient +way to check for preconditions of the system under test during runtime and skip +the test in a meaningful way. + +Based on googletest's own test code: +```c++ +class Fixture : public Test { + protected: + void SetUp() override { + GTEST_SKIP() << "skipping all tests for this fixture"; + } +}; + +TEST_F(Fixture, SkipsOneTest) { + EXPECT_EQ(5, 7); // won't fail, it won't get executed +} +``` + +The informational text is optional. + ## Teaching googletest How to Print Your Values When a test assertion such as `EXPECT_EQ` fails, googletest prints the argument