diff options
author | Derek Mauro <dmauro@google.com> | 2021-04-26 18:07:16 (GMT) |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2021-04-26 18:07:16 (GMT) |
commit | 11da093e0477185dbd78abaaa9f99db15be498d0 (patch) | |
tree | d1d88f7da4b2328642ec497c8d287ce5db4dcd34 /docs | |
parent | 23ef29555ef4789f555f1ba8c51b4c52975f0907 (diff) | |
parent | 124e87a3038a34e0761fe5f96c06ace1f7b2442a (diff) | |
download | googletest-11da093e0477185dbd78abaaa9f99db15be498d0.zip googletest-11da093e0477185dbd78abaaa9f99db15be498d0.tar.gz googletest-11da093e0477185dbd78abaaa9f99db15be498d0.tar.bz2 |
Merge pull request #3174 from sebkraemer:issue-15644
PiperOrigin-RevId: 369696657
Diffstat (limited to 'docs')
-rw-r--r-- | docs/advanced.md | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/docs/advanced.md b/docs/advanced.md index ae4d7ee..439cd3e 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -527,6 +527,38 @@ 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 the assertions `SUCCEED()` and `FAIL()`, you can prevent further test +execution at runtime with the `GTEST_SKIP()` macro. This is useful when you need +to check for preconditions of the system under test during runtime and skip +tests in a meaningful way. + +`GTEST_SKIP()` can be used in individual test cases or in the `SetUp()` methods +of classes derived from either `::testing::Environment` or `::testing::Test`. +For example: + +```c++ +TEST(SkipTest, DoesSkip) { + GTEST_SKIP() << "Skipping single test"; + EXPECT_EQ(0, 1); // Won't fail; it won't be executed +} + +class SkipFixture : public ::testing::Test { + protected: + void SetUp() override { + GTEST_SKIP() << "Skipping all tests for this fixture"; + } +}; + +// Tests for SkipFixture won't be executed. +TEST_F(SkipFixture, SkipsOneTest) { + EXPECT_EQ(5, 7); // Won't fail +} +``` + +As with assertion macros, you can stream a custom message into `GTEST_SKIP()`. + ## Teaching googletest How to Print Your Values When a test assertion such as `EXPECT_EQ` fails, googletest prints the argument |