如何使我的类的google测试类的朋友? [英] How to make google-test classes friends with my classes?
本文介绍了如何使我的类的google测试类的朋友?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我听说有可能为我的课程启用google-test TestCase类的朋友,从而使测试可以访问我的私人/受保护的成员。
I heard there is a possibility to enable google-test TestCase classes friends to my classes, thus enabling tests to access my private/protected members.
如何完成
推荐答案
尝试此操作(直接从Google测试文档...):
Try this (straight from Google Test docs...):
FRIEND_TEST(TestCaseName, TestName);
例如:
// foo.h
#include <gtest/gtest_prod.h>
// Defines FRIEND_TEST.
class Foo {
...
private:
FRIEND_TEST(FooTest, BarReturnsZeroOnNull);
int Bar(void* x);
};
// foo_test.cc
...
TEST(FooTest, BarReturnsZeroOnNull) {
Foo foo;
EXPECT_EQ(0, foo.Bar(NULL));
// Uses Foo's private member Bar().
}
这篇关于如何使我的类的google测试类的朋友?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文