5

I am using google test in a C++ project. Some functions use assert() in order to check for invalid input parameters. I already read about Death-Tests (What are Google Test, Death Tests) and started using them in my test cases.

However, I wonder if there is a way to suppress the runtime errors caused by failing assertions. At this time each failing assertion creates a pop-up window I have to close everytime I run the tests. As my project grows, this behaviour increasingly disturbs the workflow in an unacceptable way and I tend to not test assert()-assertions any longer. I know there are possibilities to disable assertions in general, but it seems more convenient to suppress the OS-generated warnings from inside the testing framework.

Community
  • 1
  • 1
jotrocken
  • 2,263
  • 3
  • 27
  • 38

1 Answers1

2

Ok, I found the solution myself: You have to select the test-style threadsafe. Just add the following line to your test code:

::testing::FLAGS_gtest_death_test_style = "threadsafe";

You can either do this for all tests in the test-binary or for affected tests only. The latter is faster. I got this from the updated FAQ: Googletest AdvancedGuide

rold2007
  • 1,297
  • 1
  • 12
  • 25
jotrocken
  • 2,263
  • 3
  • 27
  • 38