micro-test-plus 3.2.0
µTest++, a lightweight testing framework for embedded platforms
Loading...
Searching...
No Matches
Test suites

Test suites are named sequences of test cases. More...

Classes

class  micro_os_plus::micro_test_plus::test_suite
 Test suites are classes that represent a named group of test cases which self register to the runner. More...
 

Detailed Description

Test suites are named sequences of test cases.

The test cases defined in main() are considered to be part of the default (or main) test suite, and are executed immediately when invoked.

For complex applications there can be multiple test suites, usually in separate source files.

In order to make self-registration possible, test suites are classes, constructed with a name, a callable (usually a lambda which chains the execution of the test cases) and optional arguments:

class test_suite : public test_suite_base
{
public:
template <typename Callable_T, typename... Args_T>
test_suite (const char* name, Callable_T&& callable,
Args_T&&... arguments);
// ...
}
Note
It is recommended to instantiate the test suites as static objects.

The self-registration is done in the constructor. Test suites defined in different compilation units can be executed in any order (since the order in which the static constructors are invoked is not specified); thus there should be no dependencies between test suites.

The registered test suites are executed when the function exit_code() is invoked.

Examples
// Test suite with generic parameters.
static void
test_suite_args (int ic, int iv, int& ir, int* ip1, int* ip2)
{
mt::test_case ("args", [&] {
mt::expect (mt::eq (ic, 42)) << "ic is 42";
mt::expect (mt::eq (iv, 43)) << "iv is 43";
mt::expect (mt::eq (ir, 44)) << "ir is 44";
mt::expect (mt::eq (*ip1, 45)) << "*ip1 is 45";
mt::expect (mt::eq (*ip2, 46)) << "*ip2 is 46";
});
}
static int in = 43;
static int in44 = 44;
static int& ir = in44;
static int in45 = 45;
static int in46 = 46;
static int* ip2 = &in46;
static mt::test_suite ts_args
= { "Args", test_suite_args, 42, in, ir, &in45, ip2 };