使用 CppUnitTestFramework 继承
Inheritance with CppUnitTestFramework
我想创建全局类,因为我想在我的测试中进行相同的初始化。我尝试过,我多次出现诸如模棱两可的访问之类的错误。有人有想法吗?
#include <CppUnitTest.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
TEST_CLASS(GLOBAL_TEST)
{
public:
TEST_METHOD_INITIALIZE(initialize)
{
Logger::WriteMessage("INITIALIZE");
}
};
TEST_CLASS(ClassA), public GLOBAL_TEST
{
public:
TEST_METHOD(ClassA_Test1)
{
Logger::WriteMessage("ClassA_Test1");
}
};
我的错误 :
Code Description
C2385 ambiguous access of '__GetTestClassInfo'
C2385 ambiguous access of '__GetTestVersion'
C2594 'static_cast': ambiguous conversions from 'void (__cdecl ClassA::ClassA::* )(void)' to 'Microsoft::VisualStudio::CppUnitTestFramework::TestClassImpl::__voidFunc'
TEST_
宏不支持继承,但基类可以定义为包含Initialize()
方法的普通类。不过,您仍然必须在每个派生类中定义一个TEST_METHOD_INITIALIZE
函数。
#include <CppUnitTest.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
class GLOBAL_TEST
{
public:
void Initialize()
{
Logger::WriteMessage("INITIALIZE");
}
};
TEST_CLASS(ClassA), public GLOBAL_TEST
{
public:
TEST_METHOD_INITIALIZE(MethodInitialize)
{
Initialize();
}
TEST_METHOD(ClassA_Test1)
{
Logger::WriteMessage("ClassA_Test1");
}
};
相关文章:
- 继承函数的重载解析
- 继承期间显示未知行为的子类
- 头文件-继承c++
- 为什么在保护模式下继承升级不起作用
- 通过继承类使用来自不同命名空间的运算符
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 混合组合和继承的C++问题
- 继承:构造函数,初始化C++11中基类的类C数组成员
- 从类继承时,继承的类是否会通过父类重新定义继承的变量
- 公共与私人继承
- 如何创建从同一类继承的不同对象的向量
- 如何从另一个文件继承私有成员变量和公共函数
- 在模板基类中为继承类中的可选重写生成虚拟方法
- 带有继承的C++工厂
- 我应该避免多重实现继承吗
- C++继承更改成员
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 关于C++中具有多重继承"this"指针的说明
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 如何在QT Creator上将QWidget声明为继承类的对象