How to stop GTest test-case execution, when first test failed
Asked Answered
D

2

12

I'm looking for some #define which can stop test-case execution if first test failed

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
}
Davedaveda answered 9/5, 2018 at 14:21 Comment(0)
D
24

run binary with flag --gtest_break_on_failure

Davedaveda answered 17/5, 2018 at 10:13 Comment(0)
A
1

You could set the environment variable GTEST_BREAK_ON_FAILURE to something other than 0 and run the test.

Example: Let's have test executable RunTests

On Windows Command Prompt write:

> set GTEST_BREAK_ON_FAILURE=69 

Press Enter and write:

> RunTests

Press Enter

On Linux shell write:

$ export GTEST_BREAK_ON_FAILURE=69

Press Enter and write:

$ ./RunTests
Andrews answered 8/9, 2023 at 9:13 Comment(4)
please add a comment about why you don't like the answerUnseasonable
Sometimes you cannot influence the command line, but you can control the environment.Rhino
Please add an example how to use this environment variableDavedaveda
Added the example @YuriiHiertsUnseasonable

© 2022 - 2024 — McMap. All rights reserved.