谷歌测试时我对继承感到困惑。我有一个class A
具有protected
属性。如果我想访问那些我必须扩展该类,但同时我也需要扩展public ::testing::Test
唯一的目的是gtest
.
这个问题最优雅的解决方案是什么?
我也在努力避免#define protected public
为了避免在被测试类中留下测试痕迹,请使用带有固定装置的多重继承:
class ToBeTested
{
protected:
bool SensitiveInternal(int p1, int p2); // Still needs testing
}
// Google-test:
class ToBeTestedFixture : public ToBeTested, public testing::Test
{
// Empty - bridge to protected members for unit-testing
}
TEST_F(ToBeTestedFixture, TestSensitive)
{
ASSERT_TRUE(SensitiveInternal(1, 1));
ASSERT_FALSE(SensitiveInternal(-1, -1));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)