1

Here is the death test on Linux:

#include <gmock/gmock.h>
#include <cassert>

void foo()
{
    assert(false);
}

TEST(MyTestDeathTest, MyTest)
{
    ASSERT_DEATH(foo(), "");
}

int main(int argc, char** argv)
{
    ::testing::InitGoogleTest(&argc, argv);

    return RUN_ALL_TESTS();
}

Here is the output:

[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from MyTestDeathTest
[ RUN      ] MyTestDeathTest.MyTest

gtest.cpp:****:: Death tests use fork(), which is unsafe particularly in a threaded context. For this test, Google Test couldn't detect the number of threads.

[       OK ] MyTestDeathTest.MyTest (210 ms)
[----------] 1 test from MyTestDeathTest (210 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (210 ms total)
[  PASSED  ] 1 test.

If I comment out assert(false) the test fails with failed to die, but takes only 2 ms.

So I have only two death tests in my suite, but it gives me 0.5 second slowdown. Can it be helped?

JenyaKh
  • 2,040
  • 17
  • 25

0 Answers0