micro-test-plus 3.2.2
µTest++ Testing Framework
Loading...
Searching...
No Matches
Test Suites

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

Classes

class  micro_os_plus::micro_test_plus::test_suite
 Represents a named group of test cases that self-register to the runner. More...

Detailed Description

Test suites in µTest++ are named groups of related test cases, allowing for structured organisation and execution of tests. By default, all test cases defined in main() are included in the default (main) test suite and are executed immediately.

For more complex projects, multiple test suites can be defined, typically in separate source files. Test suites are implemented as classes, constructed with a name, a callable (usually a lambda that chains the execution of the test cases), and optional arguments. This design enables self-registration of test suites, ensuring they are automatically included in the test run.

It is advisable to instantiate test suites as static objects. Self-registration occurs within the constructor, and test suites defined in separate compilation units may be executed in any order, as the sequence of static constructor invocation is not specified. Therefore, test suites should not have dependencies on one another.

All registered test suites are executed when the exit_code() function is called, ensuring comprehensive test coverage across the project.

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);
// ...
}
Important
It is strongly recommended to instantiate test suites as static objects.

Self-registration is performed within the constructor, ensuring that each test suite is automatically included in the test run. When test suites are defined in separate compilation units, they may be executed in any order, as the sequence in which static constructors are invoked is not specified. Consequently, test suites should be designed to be independent and must not rely on the execution order of other suites.

All registered test suites are executed when the exit_code() function is called, guaranteeing that the entire test suite collection is run and reported in a consistent and reliable manner.

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 };
Primary namespace for the µTest++ testing framework.