...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
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:
BOOST_REQUIRE_THROW
, BOOST_TEST_REQUIRE
BOOST_CHECK_THROW
, BOOST_TEST
[6]
BOOST_WARN_THROW
, BOOST_TEST_WARN
These three levels of assertions are filtered by the framework and reported into the test log and output:
Table 3. Assertions severity levels
Level |
Test log content |
Errors counter |
Test execution |
---|---|---|---|
WARN |
warning in |
not affected |
continues |
CHECK |
error in |
increased |
continues |
REQUIRE |
fatal error in |
increased |
aborts |
The granularity of the report depends on the current log level and report level.
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. |