Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
}
like image 504
Yuriy Gyerts Avatar asked May 09 '18 14:05

Yuriy Gyerts


People also ask

How do I turn off test Gtest?

If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0 , as disabled tests are still compiled (and thus won't rot).

How do you run one test in a Gtest?

To run only some unit tests you could use --gtest_filter=Test_Cases1* command line option with value that accepts the * and ? wildcards for matching with multiple tests.

Does Gtest run tests in parallel?

gtest-parallel is a script that executes Google Test binaries in parallel, providing good speedup for single-threaded tests (on multi-core machines) and tests that do not run at 100% CPU (on single- or multi-core machines).

What is mocking in Gtest?

Mock is a method/object that simulates the behavior of a real method/object in controlled ways. Mock objects are used in unit testing. Often a method under a test calls other external services or methods within it. These are called dependencies.


1 Answers

run binary with flag --gtest_break_on_failure

like image 191
Yuriy Gyerts Avatar answered Sep 30 '22 16:09

Yuriy Gyerts