网上好多这个的转载,但是没有找到特别精简的例子,我在这编写一个,方便大家。
using ::testing::TestWithParam;
using ::testing::Bool;
using ::testing::Values;
using ::testing::Combine;
class funcTest : public TestWithParam< ::std::tr1::tuple<int , bool> >
{
protected:
virtual void SetUp()
{
a = ::std::tr1::get<0>(GetParam());
b = ::std::tr1::get<1>(GetParam());
}
virtual void TearDown()
{
}
int a;
bool b;
};
TEST_P(funcTest ,mytest__haha )
{
cout << "a = "<<a<<", b = "<<b <<" is " <<func(a , b)<<endl;
}
INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters,
funcTest,
Combine(Values(1,3) , Bool()));
[----------] 4 tests from MeaningfulTestParameters/funcTest
[ RUN ] MeaningfulTestParameters/funcTest.mytest__haha/0
a = 1, b = 0 is -1
[ OK ] MeaningfulTestParameters/funcTest.mytest__haha/0 (0 ms)
[ RUN ] MeaningfulTestParameters/funcTest.mytest__haha/1
a = 1, b = 1 is 1
[ OK ] MeaningfulTestParameters/funcTest.mytest__haha/1 (0 ms)
[ RUN ] MeaningfulTestParameters/funcTest.mytest__haha/2
a = 3, b = 0 is -3
[ OK ] MeaningfulTestParameters/funcTest.mytest__haha/2 (0 ms)
[ RUN ] MeaningfulTestParameters/funcTest.mytest__haha/3
a = 3, b = 1 is 3
[ OK ] MeaningfulTestParameters/funcTest.mytest__haha/3 (0 ms)
[----------] 4 tests from MeaningfulTestParameters/funcTest (0 ms total)