I was using Google’s gtest unit test framework today and I found an annoying problem – you can’t properly friend test methods that are in a different namespace than the class being tested.
Here is a typical situation:
namespace MyNamespace
{
class MyClass
{
public:
MyClass(int inData): data(inData){}
private:
int data;
};
}//end namespace
namespace MyNamespace
{
namespace TEST
{
class MyTestClassFixture
{
static const int fixtureData;
}
static const MyTestClassFixture::fixtureData = 5;
TEST_F(MyTestClassFixture, TestEqual)
{
MyClass testClass(5);
ASSERT_EQ(fixtureData, testClass.data);
}
}
}Continue reading “Google’s gtest not handling friend tests correctly”
