You can use typed tests or type-parameterised tests to do this.
Here's a typed test matching your example:
// A test fixture class template where 'T' will be a type you want to test
template <typename T>
class DerivedTest : public ::testing::Test {
protected:
DerivedTest() : derived_() {}
T derived_;
};
// Create a list of types, each of which will be used as the test fixture's 'T'
typedef ::testing::Types<Derived, Derived2> DerivedTypes;
TYPED_TEST_CASE(DerivedTest, DerivedTypes);
// Create test cases in a similar way to the basic TEST_F macro.
TYPED_TEST(DerivedTest, DoFoo) {
this->derived_.foo();
// TypeParam is the type of the template parameter 'T' in the fixture
TypeParam another_derived;
another_derived.foo();
}