I'm trying to use gtest type-parameterized to ensure the basic functionality of my classes. However I'm stucked in the test setup. Following is the example:
I have two classes called CatTest & DogTest, and a base class called AnimalTest that will test all the similarities of Cat & Dog:
template <typename T>
class AnimalTest : public ::testing::Test
{
public:
virtual void SetUp()
{
// Do something here so that it will call the correct setup
}
};
TYPED_TEST_P( AnimalTest , HasLegs )
{
ASSERT_EQ( 4, this->Legs );
}
REGISTER_TYPED_TEST_CASE_P( AnimalTest , HasLegs );
Now in my CatTest.cpp, I have the following macro declared ( same goes for DogTest )
typedef ::testing::Types< Cat > AnimalsTypes;
INSTANTIATE_TYPED_TEST_CASE_P( CatTest, AnimalTest , AnimalsTypes );
class CatTest : public CatSetUp
, public AnimalTest< AnimalsTypes >
{
public:
virtual void SetUp()
{
CatSetUp::SetUp();
}
}
In a normal type-parameterized test example, HasLegs test will run for both Cat and Dog type. The problem here is CatTest has its own SetUp(), and so does DogTest(). These needs to be executed in order to initialize the Cat object so I can pass it to the type-parameterized test ( Animal test ). However these SetUp is never called, in fact even the constructor of DogTest() or CatTest() was never invoked. I thought that the type parameterized test will call the corresponding instance of the derived class with the overriden SetUp() ? Or am I missing something here ?
Aucun commentaire:
Enregistrer un commentaire