When using a parametrized test in gtest where the parameters are std::pair
, when the test fails, the output is like
[ FAILED ] 1 test, listed below:
[ FAILED ] MyTest/MyFixtureTest.MyTest/1, where GetParam() = (4-byte object <03-00 00-00>, 4-byte object <02-00 00-00>)
How to pretty print the error, for example in case of enums showing the int or the enum value?
The test is something like this
enum class A
{
A=0,
B,
C
};
enum class B
{
A=0,
B,
C
};
B convertAtoB(A a)
{
if (a==A::A)
{
return B::A;
}
else if (a==A::B)
{
return B::B;
}
else
{
return B::C;
}
}
class MyFixtureTest :
public ::testing::WithParamInterface<std::pair<A, B>>
{
};
TEST_P(MyFixtureTest, MyTest) {
A a = GetParam().first;
EXPECT_EQ(convertAtoB(a), GetParam().second);
}
INSTANTIATE_TEST_CASE_P(
MyTestP,
MyFixtureTest,
::testing::Values(
std::make_pair(A::A, B::A),
std::make_pair(A::B, B::B),
std::make_pair(A::C, B::C)
)
);