这就是我所拥有的功能。

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));
}

最佳答案

TEST(SquareTests, SquareParameterRef)
{
    int result = -1;
    square2(0, result);
    EXPECT_EQ(0, result);

    square2(-2, result);
    EXPECT_EQ(4, result);
}

10-08 11:06