Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Google Test, Death Tests

I saw the documentation of that feature is seem pretty major since it's in Google Test overview features and detailed in:
https://github.com/google/googletest/blob/master/docs/advanced.md#death-tests

They look like standard assert() but they're part of Google Test, so a xUnit testing framework. Therefore, I wonder what the real usage or advantage of using those death tests are.

like image 620
Wernight Avatar asked Sep 13 '10 08:09

Wernight


People also ask

What is meant by Google Test?

Google Test (also known as gtest) is a unit testing library for the C++ programming language, based on the xUnit architecture. The library is released under the BSD 3-clause license.

What is Expect_no_throw?

EXPECT_NO_THROW. EXPECT_NO_THROW( statement ) ASSERT_NO_THROW( statement ) Verifies that statement does not throw any exception.

How do I use Google debug test?

I right-clicked on my test project and went to Debug->Start New Instance, and voila, my breakpoint was triggered. I think that's good enough.


2 Answers

The assertion is there to confirm that a function would bring about program termination if it were executed in the current process (the details explains that the death test is invoked from a subprocess which allows the tests to continue despite the death). This is useful because some code may guarantee program termination / abortion on failure (e.g. if there was an irrecoverable error), and unit tests should confirm that a function adheres to its documented behavior, regardless of what that might be.

The description on the wiki page really explains it best:

In many applications, there are assertions that can cause application failure if a condition is not met. These sanity checks, which ensure that the program is in a known good state, are there to fail at the earliest possible time after some program state is corrupted. If the assertion checks the wrong condition, then the program may proceed in an erroneous state, which could lead to memory corruption, security holes, or worse. Hence it is vitally important to test that such assertion statements work as expected.

like image 120
Michael Aaron Safyan Avatar answered Sep 28 '22 18:09

Michael Aaron Safyan


I thought the introduction in your link explained it fairly well:

In many applications, there are assertions that can cause application failure if a condition is not met. These sanity checks, which ensure that the program is in a known good state, are there to fail at the earliest possible time after some program state is corrupted. If the assertion checks the wrong condition, then the program may proceed in an erroneous state, which could lead to memory corruption, security holes, or worse. Hence it is vitally important to test that such assertion statements work as expected.

Since these precondition checks cause the processes to die, we call such tests death tests. More generally, any test that checks that a program terminates in an expected fashion is also a death test.

What bit of that doesn't make sense?

like image 45
Jon Cage Avatar answered Sep 28 '22 18:09

Jon Cage