Unit test library in BOOST

xiaoxiao2021-03-06  39

#include using boost :: unit_test :: test_suite; void force_division_by_zero () {// unit test framework can catch operating system signals BOOST_CHECKPOINT ( "About to force division by zero!"); int i = 1, j = 0; i = I / j;} void infinite_loop () {// unit test framework can break infinite loops by timeout # ifdef __unix // Don't Have Timeout on Other Platforms Boost_CheckPoint ("About to Enter AN infinite loop! "); while (1); # else BOOST_MESSAGE (" Timeout support is not implemented on your platform "); # endif} test_suite * init_unit_test_suite (int argc, char * argv []) {test_suite * test = BOOST_TEST_SUITE ( "Unit Test EXAMPLE 2"); test-> add (& force_case (& force_diVision_by_zero); test-> add (& infinite_case_loop), 0, / * timeout * / 2); return test;} // EOF output: Running 2 Test case ... Exception in "force_division_by_zero": Signal: Sigfpe (Arithmetic Exception) T7.cpp (7): Last Checkpoint: About To Force Division By ZERO! EXCEPTION IN "infinite_loop": Signal: SigalRM (Timeout While Executing Function) T7.cpp (16): Last Checkpoint: About To Enter An Infinite Loop!

*** Errors Detected in Test Suite "Unit Test Example 2"; See Standard Output for Details

转载请注明原文地址:https://www.9cbs.com/read-54036.html

New Post(0)