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

Assertion severity level
PrevUpHomeNext

There are three levels of assertions and all the testing tools are supplied in these three flavours/levels. These levels have different meaning on the consistency of the test case:

  • REQUIRE which implements a requirements : this is a strong condition for the operations following the assertion to be valid. This type of assertions should be used when a pre-condition for running the test is not met or when the test-case cannot continue. If such as assertion fails, the test case execution stops immediately, and the test-case is flagged as failed.
  • CHECK for standard checks: this is the most commonly used assertion level. If the statement evaluates to false, the test case is flagged as failed but its execution continues.
  • WARN which stands for warnings: this is an assertion providing information. The test case execution continues and a warning message is logged. The warning does not change the success status of a test case. This level of assertion can be used to validate aspects less important then correctness: performance, portability, usability, etc.

For example:

These three levels of assertions are filtered by the framework and reported into the test log and output:

  1. If an assertion designated by the tool passes, confirmation message can be printed in log output [7].
  2. If an assertion designated by the tool fails, the following will happen, depending on the assertion level [8]:

Table 3. Assertions severity levels

Level

Test log content

Errors counter

Test execution

WARN

warning in <test-case-name>: condition <assertion description> is not satisfied

not affected

continues

CHECK

error in <test-case-name>: test <assertion description> failed

increased

continues

REQUIRE

fatal error in <test-case-name>: critical test <assertion description> failed

increased

aborts


The granularity of the report depends on the current log level and report level.

[Note] Note

in the above table, the test execution is related to the current test case only. Hence "aborts" means that the current test case is aborted, but other test cases in the test tree are still executed.



[6] BOOST_TEST is equivalent to BOOST_TEST_CHECK

[7] to manage what messages appear in the test log stream, set the proper log_level

[8] in some cases log message can be slightly different to reflect failed tool specifics, see here


PrevUpHomeNext