Stop executing test.

867 views
Skip to first unread message

Jarek K.

unread,
Jan 25, 2011, 10:21:04 AM1/25/11
to Google C++ Testing Framework
Hi all,

I have a problem with my tests. I'm trying to test some function, lets
say foo(),
and within this function there is some null checking done at the very
beginning and if some of the pointers are null
function void crash() is called which causes to reset the box. I would
like to stub crash() for my testing purposes
so that whenever it is called the particular test would be aborted
with failure (only this test not whole suite).
I tried to put GTEST_FAIL() macro in crash() and the test fails
alright but it continues to run which causes that test writes that all
assertions and expectations fail. Is there any way to abort the test
and continue to the next one?

Thanks.
J.

Joey Oravec

unread,
Jan 25, 2011, 10:44:02 AM1/25/11
to Jarek K., Google C++ Testing Framework
The problem is that the gtest macros control flow using "return". It sounds like you expected the TEST() to quit. Actually the macro set a failure and called return, which returned from the subroutine. See this link for details:
 
 
You probably want to add an ASSERT_NO_FATAL_FAILURE() after each subroutine call to percolate the error upwards and return from the entire TEST()
 
-joey
Reply all
Reply to author
Forward
0 new messages