Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Time-out for test cases

The Unit Test Framework provides the decorator timeout that specifies a time-out for a specific test case, The argument time (in seconds) sets the maximum allowed duration of a test case. If this time is exceeded the test case is forced to stop and is reported as failure.

Example: decorator timeout

Code

#define BOOST_TEST_MODULE decorator_11
#include <boost/test/included/unit_test.hpp>
namespace utf = boost::unit_test;

BOOST_AUTO_TEST_CASE(test1, * utf::timeout(2))
{
#ifdef BOOST_SIGACTION_BASED_SIGNAL_HANDLING
  for(;;) {}
  BOOST_TEST(true);
#else
  BOOST_TEST(false);
#endif
}

Output

> decorator_11
Running 1 test case...
unknown location(0): fatal error: in "test1": signal: SIGALRM (timeout while executing function)
test.cpp(5): last checkpoint: "test1" entry.

*** 1 failures is detected in test module "decorator_11"
[Note] Note

Applied at test suite level, this decorator has no effect.

[Caution] Caution

Decorator timeout has no effect on Windows build. This feature is not implemented on Windows yet.


PrevUpHomeNext