简体   繁体   English

如何在发行版中排除测试用例(gTest)

[英]How to exclude test cases in release (gTest)

If I'd use g(oogle)Test, these litte google macros like FRIEND_TEST(Test, Proc) are distributed everywhere in my code. 如果我要使用g(oogle)Test,则这些FRIEND_TEST(Test, Proc)类的Google宏宏会分布在我的代码中的各处。 Is there an automatism to exclude them from build, or do I really have to surround those with #ifdefs ? 是否有自动机制将它们从构建中排除,或者我真的必须用#ifdefs包围它们吗?

You don't need to do anything of the sort. 您无需执行任何操作。 friend declarations are totally harmless and don't produce any overhead in production code. friend声明是完全无害的,不会在生产代码中产生任何开销。

You can have friend GTest cases, as mentionned here 您可以在这里提到朋友GTest案例

How to make google-test classes friends with my classes? 如何与我的班级成为Google测试班级的朋友?

As said, there is no overhead to using these macros. 如前所述,使用这些宏没有任何开销。

Also, you can work around to test private class members without using FRIEND_TEST . 另外,您可以不使用FRIEND_TEST来测试私人班级成员。 One of them is to write accessors for the tested class' private members in the fixture class, then use the accessors in your tests: 其中之一是为夹具类中的测试类的私有成员编写访问器,然后在测试中使用访问器:

class Foo {
  friend class FooTest;
  ...
};

class FooTest : public ::testing::Test {
 protected:
  ...
  T1 get_private_member1(Foo* obj) {
    return obj->private_member1_;
  }
};

TEST_F(FooTest, Test1) {
  ...
  get_private_member1(x)
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM