开发者

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

开发者 https://www.devze.com 2023-03-19 18:26 出处:网络
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 us

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 t开发者_开发技巧o suppress the OS-generated warnings from inside the testing framework.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消