I'm using Google Test for my C++ code recently. When I read how to setup the test fixture for tests, I get a little bit confused. The Writing the main() Function session showed an example about what the test fixture class looks like. However, when it comes tothe constructor definitions, should we put it just inside the test fixture class? For example, like the following code snippet given by google test doc:
class FooTest : public ::testing::Test {
protected:
// You can remove any or all of the following functions if its body
// is empty.
FooTest() {
// You can do set-up work for each test here.
}
virtual ~FooTest() {
// You can do clean-up work that doesn't throw exceptions here.
}
}
I also looked at the definition of the macro TEST_F(test_fixture_name, test_name)
, it seems like for each test associated with the same test fixture, the macro will create a new subclass of the test fixture class.
Given the above fact,
if the constructor's work is heavy, does that mean the implicitly
inline
of the test fixture's constructor will let the compiler expand the constructor's large pieces of code everywhere? (or this doesn't matter in the same translation unit?)Does it make more sense to define the constructor outside of the test fixture class in this situation? But this will make the test code less readable, I don't really know what to do..
Could anybody give me some suggestions on this? Thanks!