有没有办法在 google 测试中指定某些测试需要通过此测试

Is there a way to specify in google tests that certain tests need to have passed for this test

在 google 测试中有没有办法表明某个测试应该已经通过。我想为测试指定一些先决条件。 例子

TEST(Category, Eat)
{
}
TEST(Category, Sleep)
{
}

TEST(Category, Grow)
{
   //Eat and Sleep tests must have passed.
}

有没有办法让我在 Test Grow 中指出 Eat 和 Sleep 测试应该已经通过?

您可以在 "Eat" 和 "Sleep" 中使用致命断言 (ASSERT_...) 而不是非致命断言 (EXPECT_...)。如果在 "Eat" 和 "Sleep" 之后添加 "Grow",如果其中任何一个失败,则不会执行。