如何使用googletest引用参数测试void函数与通?

问题描述 投票:0回答:1

这是我具备的功能。

int square(const int value)
{
    return value * value;
}

void square2(const int value, int& output)
{
    output = value * value;
}

我没有问题可以测试方。但我怎么测试square2?

这是我目前正在测试。

TEST(SquareTests, Square)
{
    EXPECT_EQ(0, square(0));
    EXPECT_EQ(4, square(-2));
}

TEST(SquareTests, SquareParameter)
{
    //EXPECT_EQ(0, square2(0));
    //EXPECT_EQ(4, square2(-2));
}
c++ googletest
1个回答
3
投票
TEST(SquareTests, SquareParameterRef)
{
    int result = -1;
    square2(0, result);
    EXPECT_EQ(0, result);

    square2(-2, result);
    EXPECT_EQ(4, result);
}
© www.soinside.com 2019 - 2024. All rights reserved.