CppUnit project page | CppUnit home page |
There is mainly two ways to create test case:
A test case is usually created using CppUT::makeTestCase() that instantiate CppUT::TestCase.
Notes that test case instantiation is usually only done when you need to create your own convenience test case macro or you are populating a TestSuite with parametrized TestCase. The framework provides severable way to create and register test case, see Creating TestCase: light Fixture, Creating TestCase: TestFixture, Creating TestCase: test functions.
The difference between aborting and non-aborting assertions is that if an aborting assertion fails then the test is aborted, while if a non-aborting assertion failed, then the assertion is logged and the test continue. In CppUnit 1 only aborting assertion were provided.
When an aborting assertion failed, it throws the exception CppUT::AbortingAssertionException to abort the test. You must ensure that your test let this exception pass through (notes that it subclasses std::runtime_error).
All assertions are macros (to capture source location). By convention, the following naming prefix are used do distinguish aborting and non-aborting assertion:
In the table below, all supported assertions without the above prefix will be listed.
Suffix | Parameters | Asserts that... |
expression , [message ] | expression is true | |
_EXPR | expression | expression is true |
_FALSE | expression , [message ] | expression is false |
_EXPR_FALSE | expression | expression is false |
_EQUAL | expected_value , actual_value , [message ] | expected_value == actual_value |
_NOT_EQUAL | expected_value , actual_value , [message ] | expected_value != actual_value |
_DOUBLE_EQUAL | expected_value , actual_value , tolerance , [message ] | fabs (expected_value - actual_value ) <= tolerance |
_THROW | expression , ExpectedExceptionType | expression throws an exception of type ExpectedExceptionType |
_NO_THROW | expression | expression does not throw any exceptions |
_ASSERTION_FAIL_MESSAGE | assertion , message | assertion fails |
_ASSERTION_FAIL | assertion | assertion fails |
_ASSERTION_PASS_MESSAGE | assertion , message | assertion passes |
_ASSERTION_PASS | assertion | assertion passes |
STR_START | pattern , actual_string | actual_string starts with pattern |
STR_END | pattern , actual_string | actual_string ends with pattern |
STR_END | pattern , actual_string | actual_string ends with pattern |
STR_CONTAIN | pattern , actual_string | actual_string contains pattern |
STR_EQUAL | pattern , actual_string | actual_string contains pattern |
_SEQUENCE_EQUAL | expected_ordered_sequence , actual_ordered_sequence | expected_ordered_sequence and actual_ordered_sequence contains the same value in the same order. |
_SET_EQUAL | expected_unordered , actual_unordered_sequence | expected_ordered_sequence and actual_ordered_sequence contains the same value regardless of the order. |
_STL_SEQUENCE_EQUAL | expected_ordered_sequence , actual_ordered_sequence | expected_ordered_sequence and actual_ordered_sequence contains the same value in the same order. |
_STL_SET_EQUAL | expected_unordered , actual_unordered_sequence | expected_ordered_sequence and actual_ordered_sequence contains the same value regardless of the order. |
See module Assertions for the list of assertion macros.
[[notes: add double brace warning about macro parameter]]
Use CPPUT_IGNORE_FAILURE() to ignore an assertion failure. See ignore_failure_demo for an example.
message
parameter of the assertion).CppUT::log() can be used to log a context. The list of log events and assertion failures is seen as a single test event sequence. See log_demo for an example.
Notes that a SkipTestException exception (a subclass of std::runtime_error) is thrown to abort the test.
A TestFixture support the following features:
On the positive side, it is easier on the wrist.
They usually rely on a reflection mecanism for interaction between the input data and testing.
Currently, only column based fixture is implemented. Data takes the form of a table. The header row indicates the role of each column. For each row, the same sequence of operation will be done:
The CppUT and OpenTest library are under the LGPL with run-time exception.
|
hosts this site. |
Send comments to: CppUnit Developers |