1 / 11

Google C++ Testing Framework

Google C++ Testing Framework. Death Tests. Death Tests. In many applications, there are assertions that can cause application failure if a condition is not met. Square root function to check negative input

hamal
Download Presentation

Google C++ Testing Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Google C++ Testing Framework Death Tests

  2. Death Tests • In many applications, there are assertions that can cause application failure if a condition is not met. • Square root function to check negative input • 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.

  3. Test Square Root

  4. Test negative input ASSERT_EXIT(statement, predicate, expected_message) Predefined predicate: ::testing::ExitedWithCode(exit_code). The result of this predicate is true only if the program exits with the same exit_code mentioned in the predicate. ASSERT_DEATH(statement, expected_message) ASSERT_DEATH is simpler than ASSERT_EXIT; it just compares the error message in standard error with whatever is the user-expected message.

  5. Tests Execution

  6. Macros Support Death Tests statement: a statement that is expected to cause the process to die,  predicate:a function or function object that evaluates an integer exit status:regex is a regular expression that the stderr output of statement is expected to match. Note that statement can be any valid statement(including compound statement) and doesn't have to be an expression. As usual, the ASSERT variants abort the current test function, while the EXPECT variants do not.

  7. What crash means? • means that the process terminates with a non-zero exit status code. • either the process has called exit(non-zero value) or _exit(non-zero value) , or • it may be killed by a signal. • means that if statement terminates the process with a 0 exit code, it is not considered a crash by EXPECT_DEATH. • Use EXPECT_EXIT instead if this is the case, or if you want to restrict the exit code more precisely.

  8. Predicate  • must accept an int and return a bool. The death test succeeds only if the predicate returns true.

  9. Death test only cares about three things • does statement abort or exit the process? • (in the case of ASSERT_EXIT and EXPECT_EXIT) does the exit status satisfy predicate? Or (in the case of ASSERT_DEATH and EXPECT_DEATH) is the exit status non-zero? And • does the stderr output match regex?

  10. Regular Expression Syntax

More Related