gpt4 book ai didi

c++ - GoogleTest:如何跳过测试?

转载 作者:行者123 更新时间:2023-12-03 04:44:15 32 4
gpt4 key购买 nike

使用 Google Test 1.6(Windows 7、Visual Studio C++)。如何关闭给定的测试? (又名如何阻止测试运行)。除了注释掉整个测试之外,我还能做些什么吗?

最佳答案

docs适用于 Google 测试 1.7 suggest :

If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0, as disabled tests are still compiled (and thus won't rot).

上述文档中的示例:

// Tests that Foo does Abc.
TEST(FooTest, DISABLED_DoesAbc) { ... }

class DISABLED_BarTest : public testing::Test { ... };

// Tests that Bar does Xyz.
TEST_F(DISABLED_BarTest, DoesXyz) { ... }

如果您可以访问更新版本的 Google Test(当前版本是 v1.12.1),请查看 jslmsca 在评论中和 Peter Bloomfield 在另一个答案中建议的 GTEST_SKIP() 宏。来自advanced.md中的示例:

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
}

关于c++ - GoogleTest:如何跳过测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7208070/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com