当第一次测试失败时如何停止 GTest 测试用例执行

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

我正在寻找一些

#define
,如果第一次测试失败,它可以停止测试用例的执行

TEST_F(TestInitializer, 1st-test) {
  Initiator.call();      
  EXPECT_CALL(mock_obj, onAction(false)).Times(AtLeast(0));

  // some define I want
  ::testing::stopIfFailed();
}

TEST_F(TestInitializer, 2nd-test) {
  // this test must not be executed if first test failed
}
unit-testing integration-testing googletest googlemock
2个回答
23
投票

使用标志运行二进制文件

--gtest_break_on_failure


0
投票

您可以将环境变量

GTEST_BREAK_ON_FAILURE
设置为0以外的值并运行测试。

示例:让我们来测试可执行文件 RunTests

Windows 命令提示符下写入:

> set GTEST_BREAK_ON_FAILURE=69 

按 Enter 键并写入:

> RunTests

按输入键

Linux shell 上写入:

$ export GTEST_BREAK_ON_FAILURE=69

按 Enter 键并写入:

$ ./RunTests
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.