Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress runtime errors caused by assert() using google test?

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.

like image 876
jotrocken Avatar asked Nov 05 '22 18:11

jotrocken


1 Answers

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

like image 136
jotrocken Avatar answered Nov 12 '22 15:11

jotrocken