You should be able to separate the gtest class declarations from the definitions in the usual way using .hpp and .cpp files.
So rather than defining the test functions and fixtures in the header, move these to a source file which #include
s the header. So if e.g. you have test.hpp
as:
#include "gtest/gtest.h"
class MyTest : public ::testing::Test {
protected:
void TestFunction(int i) {
ASSERT_GT(10, i);
}
};
TEST_F(MyTest, first_test) {
ASSERT_NE(1, 2);
TestFunction(9);
}
change test.hpp
to:
#include "gtest/gtest.h"
class MyTest : public ::testing::Test {
protected:
void TestFunction(int i);
};
and add test.cpp
:
#include "test.hpp"
void MyTest::TestFunction(int i) {
ASSERT_GT(10, i);
}
TEST_F(MyTest, first_test) {
ASSERT_NE(1, 2);
TestFunction(9);
}
If you're including the same test header in multiple places are you really looking for typed tests or type-parameterised tests? See http://code.google.com/p/googletest/wiki/V1_6_AdvancedGuide#Typed_Tests for further details.