gtest参数化之Combine

1 篇文章 0 订阅

网上好多这个的转载,但是没有找到特别精简的例子,我在这编写一个,方便大家。

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)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值