From 71874246c3a054977d94fd4729576484c2af62e9 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 6 Dec 2010 22:18:59 +0000 Subject: Allows a value-parameterized test fixture to derive from Test and WithParamInterface separately; contributed by Matt Austern. git-svn-id: http://googletest.googlecode.com/svn/trunk@526 861a406c-534a-0410-8894-cb66d6ee9925 --- include/gtest/gtest-param-test.h.pump | 45 +++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'include/gtest/gtest-param-test.h.pump') diff --git a/include/gtest/gtest-param-test.h.pump b/include/gtest/gtest-param-test.h.pump index cff9972..d73f24d 100644 --- a/include/gtest/gtest-param-test.h.pump +++ b/include/gtest/gtest-param-test.h.pump @@ -49,10 +49,12 @@ $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support. #if 0 // To write value-parameterized tests, first you should define a fixture -// class. It must be derived from testing::TestWithParam, where T is -// the type of your parameter values. TestWithParam is itself derived -// from testing::Test. T can be any copyable type. If it's a raw pointer, -// you are responsible for managing the lifespan of the pointed values. +// class. It is usually derived from testing::TestWithParam (see below for +// another inheritance scheme that's sometimes useful in more complicated +// class hierarchies), where the type of your parameter values. +// TestWithParam is itself derived from testing::Test. T can be any +// copyable type. If it's a raw pointer, you are responsible for managing the +// lifespan of the pointed values. class FooTest : public ::testing::TestWithParam { // You can implement all the usual class fixture members here. @@ -134,9 +136,12 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets)); // in the given test case, whether their definitions come before or // AFTER the INSTANTIATE_TEST_CASE_P statement. // -// Please also note that generator expressions are evaluated in -// RUN_ALL_TESTS(), after main() has started. This allows evaluation of -// parameter list based on command line parameters. +// Please also note that generator expressions (including parameters to the +// generators) are evaluated in InitGoogleTest(), after main() has started. +// This allows the user on one hand, to adjust generator parameters in order +// to dynamically determine a set of tests to run and on the other hand, +// give the user a chance to inspect the generated tests with Google Test +// reflection API before RUN_ALL_TESTS() is executed. // // You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc // for more examples. @@ -144,6 +149,32 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets)); // In the future, we plan to publish the API for defining new parameter // generators. But for now this interface remains part of the internal // implementation and is subject to change. +// +// +// A parameterized test fixture must be derived from testing::Test and from +// testing::WithParamInterface, where T is the type of the parameter +// values. Inheriting from TestWithParam satisfies that requirement because +// TestWithParam inherits from both Test and WithParamInterface. In more +// complicated hierarchies, however, it is occasionally useful to inherit +// separately from Test and WithParamInterface. For example: + +class BaseTest : public ::testing::Test { + // You can inherit all the usual members for a non-parameterized test + // fixture here. +}; + +class DerivedTest : public BaseTest, public ::testing::WithParamInterface { + // The usual test fixture members go here too. +}; + +TEST_F(BaseTest, HasFoo) { + // This is an ordinary non-parameterized test. +} + +TEST_P(DerivedTest, DoesBlah) { + // GetParam works just the same here as if you inherit from TestWithParam. + EXPECT_TRUE(foo.Blah(GetParam())); +} #endif // 0 -- cgit v1.2.3