六、顯示返回成功或失敗
直接返回成功:SUCCEED();
返回失。
TEST(ExplicitTest, Demo)
{
ADD_FAILURE() << "Sorry"; // None Fatal Asserton,繼續(xù)往下執(zhí)行。
//FAIL(); // Fatal Assertion, 不往下執(zhí)行該案例。
SUCCEED();
}
七、異常檢查
例如:
int Foo(int a, int b)
{
if (a == 0 || b == 0)
{
throw "don't do that";
}
int c = a % b;
if (c == 0)
return b;
return Foo(b, c);
}
TEST(FooTest, HandleZeroInput)
{
EXPECT_ANY_THROW(Foo(10, 0));
EXPECT_THROW(Foo(0, 5), char*);
}