is it possible to define a base test-fixture with (abstract) test cases and derive classes from them?
There are two szenarios I'd like to support (Taken from Roy Overshores "The art of Unit Testing"):
- Template test class pattern Define abstract test cases in the base test-fixture and thus force derived classes to implement them.
- Abstract test driver class pattern Implement tests in the base class that all derived class inherit automatically
I cannot figure out how this works with googletest. If I have a base class
#pragma once class BaseClass : public ::testing::Test { }; TEST_F(BaseClass, T1) { } and two derived classes (in different files)
#include "stdafx.h" #include "BaseClass.h" class DerivedClass1 : public BaseClass { }; and
#include "stdafx.h" #include "BaseClass.h" class DerivedClass2 : public BaseClass { }; I get the compiler error
virtual void __thiscall BaseClass_T1_Test::TestBody(void)" (?TestBody@BaseClass_T1_Test@@EAEXXZ) already defined in DerivedClass1.obj Is it somehow possible to define concrete and pure virtual tests in a test base class?