'exiting on FATAL asserts in google test framework
Is there any option or method to exit from google test framework completely without executing any further tests when we have identified a FATAL assert which renders any further testing useless ?
Solution 1:[1]
There is no specific mechanism provided by the library to abort execution, but nothing prevents you from using a standard assertion to abort program execution.
#include <cassert>
TEST(TestSuite, TestCase)
{
assert(<fatal condition>);
// ...
}
If the fatal condition is the result of some test setup that you can control, you might be interested in learning about Google Test's support for Death Tests.
Solution 2:[2]
One way to handle this is to use the GTEST_FATAL_FAILURE_ macro. You can use it like this
#include <gtest/gtest.h>
TEST(TestSuite, TestCase)
{
// ...
if (somethingHappens) {
GTEST_FATAL_FAILURE_("Text to display when the failure happens");
}
}
When triggered you will see this in the CLI
/home/yourname/yourpath/yourfile.cpp:13: Failure
Text to display when the failure happens
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Antonio Pérez |
| Solution 2 | Mark Daams |
