如何让 VS TEST_CLASS(SomeTestClassName) 成为我正在测试的类的 friend ? 我是 c++ 的新手,在网上找不到任何信息。 如果是简单的添加
friend class SomeTestClassName;
到被测试的类的标题 - 这是行不通的。
添加示例:
#include "..\CoreTests\ChallengeManagerTests.cpp" //Circular reference? But forward declaration don't works
class ChallengeManager
{
private:
void PrivateMethod();
public:
void PublicMethod();
friend class CoreTests::ChallengeManagerTests; // Compiler can't find ChallengeManagerTests in CoreTests namespace. Forward declaration give class redefinition error.
}
//ChallengeManagerTests:
#include "stdafx.h"
#include "CppUnitTest.h"
#include "..\Core\ChallengeManager.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Brans;
namespace CoreTests
{
TEST_CLASS(ChallengeManagerTests)
{
public:
TEST_METHOD(RandomInputs)
{
Brans::ChallengeManager cm;
cm. // here i got is not accessible error for private members
}
};
}
最佳答案
从您删除的上一个问题来看,您的测试类名称是在命名空间内定义的,因此您需要在 friend 声明中提供相同的命名空间。
关于c++ - 我怎样才能结交 AND TEST CLASS(SomeTest ClassName) friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19520670/