There is another option that you have not included, while others may stumble on this issue without knowing the solution.
In fact, you can get any arbitrary type by looking at the macro itself:
/////////////////////////////////////////////////////////////////////////////////////////// // Macro to define your test class. // Note that you can only define your test class at namespace scope, // otherwise the compiler will raise an error. #define TEST_CLASS(className) \ ONLY_USED_AT_NAMESPACE_SCOPE class className : public ::Microsoft::VisualStudio::CppUnitTestFramework::TestClass<className>
Since C ++ supports multiple inheritance, you can easily get code similar to the following:
class ParentClass { public: ParentClass(); virtual ~ParentClass(); }; TEST_CLASS(MyTestClass), public ParentClass { };
Just remember that if you work with resources, you will need to have a virtual destructor for it to be called. You will also need to directly call the initialization and cleanup methods if you intend to use them, because the static methods that they create are not called automatically.
Good luck, good testing!
source share