Test suites
Test suites are named groups of related test cases. More...
Classes Index
| class | located_name |
|
A name of a suite or of a test case, with the location where it was given. More... | |
| class | static_suite |
|
A test suite designed for static (namespace-scope) registration with a runner. More... | |
| class | suite |
|
A named, runnable test suite registered with the test runner. More... | |
| class | top_suite |
|
The optional top suite owned by every runner instance. More... | |
Description
Test suites are named groups of related test cases.
A suite has a name and a body, a function that creates its test cases. The suites are either added in main() with runner::add_suite(), or defined as static suites, and runner::run_suites() runs them all, sorted by name.
The top suite is a shortcut: a suite whose body is the code of main() itself. runner::add_top_suite() adds it and returns it, and the test cases created on it in main() run immediately, before runner::run_suites() is called. It therefore always runs before all the other suites, whatever their names. It is optional; a program may put all its test cases in the other suites.
A test case can be created only on the suite whose body is running: on the top suite from main(), or on the suite received by the body of another suite. A call on another suite, for example on the top suite captured in the body of another suite, is reported as a failure, and the test case is not run.
The static suites are mt::static_suite objects, defined at namespace scope, usually in separate source files, and constructed with a name, a reference to the runner, and a callable (usually a function or a lambda with a mt::suite& first parameter, which creates the test cases), along with any optional arguments. They register themselves in their constructors, so they are included in the test run without other calls.
The runner referred to by the static suites in other source files must have external linkage (not static), and be declared extern in a header shared by these files.
A static suite does not need the runner to be constructed first; it can be defined in any source file, before or after the runner.
- Execution order
-
The top suite runs first, as described above. runner::run_suites() then runs all the other suites, the added and the static ones together, sorted by name:
- the names are compared byte by byte, as by std::strcmp(), so the upper-case letters come before the lower-case ones ("Gamma" runs before "alpha");
- suites with the same name run in the order in which they were created; the static suites are created before main() starts, so they run before the added suites with the same name;
- the order of static suites with the same name, defined in different source files, is not specified; give them distinct names.
To set the order explicitly, start the names with zero-padded numbers ("01 - Init", "02 - Run"). Even so, write each suite so that it does not depend on the others having run before it.
- Examples
Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.