如何让 VS TEST_CLASS(SomeTestClassName) 成为我正在测试的班级的朋友?我是 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
}
};
}