正在使用friend_test要做的正确的事情
Is using FRIEND_TEST the right thing to do?
当我在https://github.com/google/googletest/googletest/blob/master/googletest/googletest/gtest/gtest/gtest/gtest_prod.h- https://github.com/googletest/googletest/googletest/googletest/googletest/googletest/googletest/googletest/googletest/googletest/grood.h https://github.com/googletest/googletest/googletest/grood.h中进行
:
#ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_
#define GTEST_INCLUDE_GTEST_GTEST_PROD_H_
// When you need to test the private or protected members of a class,
// use the FRIEND_TEST macro to declare your tests as friends of the
// class. For example:
//
// class MyClass {
// private:
// void MyMethod();
// FRIEND_TEST(MyClassTest, MyMethod);
// };
//
// class MyClassTest : public testing::Test {
// // ...
// };
//
// TEST_F(MyClassTest, MyMethod) {
// // Can call MyClass::MyMethod() here.
// }
#define FRIEND_TEST(test_case_name, test_name)
friend class test_case_name##_##test_name##_Test
#endif
如果我的理解是正确的,则测试类是无条件地成为生产类别的孩子。这将使生产类取决于测试类。实际上,生产代码也将包含我的测试库。
我不确定这是否正确。
我在这里错过了什么,还是应该有条件地汇编?
谢谢。
我不会那样阅读。如果需要,您可以将不存在的不存在的班级作为您的生产班的朋友。它是无害的,当然不会引入依赖关系或在您的生产代码中添加测试代码。
class Production
{
friend class WibbleWibble;
...
};
即使不存在WibbleWibble,此代码也是完全正确的。因此没有依赖性。
相关文章:
- 如何取消对nullptr的屏蔽,返回正确的对象
- 使用C++程序合并排序没有得到正确的输出
- g++ 说函数不存在,即使包含正确的标头
- 对可变参数使用声明.如何选择正确的功能
- 在我的代码中,获得最大的Pair Wise产品C++和输出并不总是正确的
- 密码登录程序将永远循环并显示不正确的结果
- 在C++中返回不正确的楼层函数值
- (SFML)按下键时,播放器构造函数未使用正确的动画进行更新
- 特征 LLT 模块给出不正确的结果?
- 为什么我的 if else 语句不起作用并从数组中输出正确的索引?
- 不正确的操作数类型 MSVC
- 数组填充了不正确的值
- C++正确的指针成员初始化
- 制作文件:没有规则来制定目标:如何设置正确的规则?
- Visual C++: MSVC vs. GCC+CLANG: 处理 lambda 捕获类成员变量,正确的方法是什么?
- 无法使用 g++ 从多个文件接收正确的输出
- 为什么 sizeof 在 C++ 中给出不正确的字节数?
- atoi() 在应用于大型命令行参数时会产生不正确的值
- Clang 给了我符号更改的警告,但代码仍然产生正确的输出
- 系统( "pause" ) 即使使用正确的标头也无法正常工作