|
micro-test-plus 4.1.0
µTest++ Testing Framework
|
A named, runnable test suite registered with the test runner. More...
#include <micro-os-plus/micro-test-plus.h>
Public Member Functions | |
| template<typename Callable_T, typename... Args_T> | |
| suite (const char *name, class runner &runner, Callable_T &&callable, Args_T &&... arguments) | |
| Constructs a suite with a name, runner, and callable body. | |
| suite (const suite &)=delete | |
| Deleted copy constructor to prevent copying. | |
| suite (suite &&)=delete | |
| Deleted move constructor to prevent moving. | |
| virtual | ~suite () override |
| Virtual destructor. | |
| void | abort (const reflection::source_location &sl=reflection::source_location::current()) |
| Aborts test execution via the owning runner. | |
| size_t | children_subtests_count (void) const noexcept |
| Returns the number of direct child subtests owned by this node. | |
| size_t | current_subtest_index () const noexcept |
| Returns the index of the most recently created child subtest. | |
| size_t | increment_subtest_index () noexcept |
| Increments and returns the child subtest sequential index. | |
| const char * | name (void) const noexcept |
| Gets the node name. | |
| suite & | operator= (const suite &)=delete |
| Deleted copy assignment operator to prevent copying. | |
| suite & | operator= (suite &&)=delete |
| Deleted move assignment operator to prevent moving. | |
| size_t | own_index () const noexcept |
| Returns the positional index of this object within its parent. | |
| void | own_index (size_t index) noexcept |
| Sets the positional index of this object within its parent. | |
| class reporter & | reporter (void) const noexcept |
| Gets the test reporter associated with this test runnable. | |
| virtual void | run (void) override |
| Executes the suite body by invoking the stored callable. | |
| class runner & | runner (void) const noexcept |
| Gets the test runner associated with this test runnable. | |
| template<typename Callable_T, typename... Args_T> | |
| void | test (const char *name, Callable_T &&callable, Args_T &&... arguments) |
| Adds a test case to the suite. | |
| const detail::timestamps & | timings () const noexcept |
| Gets the timings for this suite (const overload). | |
| detail::timestamps & | timings () noexcept |
| Gets the timings for this suite. | |
| const runner_totals & | totals () const noexcept |
| Gets the totals for the test (const overload). | |
| runner_totals & | totals () noexcept |
| Gets the totals for the test. | |
Protected Member Functions | |
| void | after_subtest_create_ (std::unique_ptr< subtest > child_test, suite &suite) |
| Registers a newly constructed child subtest and executes it immediately. | |
Protected Attributes | |
| std::function< void(suite &)> | callable_ |
| Callable storing the test body and any bound arguments. Invoked with a reference to the derived Self_T instance. | |
| std::vector< std::unique_ptr< subtest > > | children_subtests_ |
| Owning collection of direct child subtests. | |
| size_t | current_subtest_index_ |
| The subtest index, counting from 1. | |
| const char * | name_ |
| The test node name. | |
| size_t | own_index_ |
| The test index, counting from 1. | |
| class runner & | runner_ |
| Reference to the test runner that owns this object. | |
| detail::timestamps | timings_ |
| Timing measurements for this suite's execution. | |
| runner_totals | totals_ |
| Totals for the test node, including nested cases. | |
suite represents a top-level named group of related test cases within the µTest++ framework. It is created by calling runner::suite(), which constructs the object, stores it in the runner's collection, and runs it immediately. Each suite records its own timing information and propagates its results to the owning runner.
The body of a suite is supplied as a callable (typically a lambda) that receives a suite& reference as its first argument. Inside the body, suite::test() is called to create and run individual subtests.
The class is non-copyable and non-movable to preserve unique ownership and consistent state throughout the test session.
| micro_os_plus::micro_test_plus::suite::suite | ( | const char * | name, |
| class runner & | runner, | ||
| Callable_T && | callable, | ||
| Args_T &&... | arguments ) |
| Callable_T | The type of the callable object. |
| Args_T | The types of any additional callable arguments. |
| [in] | name | The suite name or description, used in reports. |
| [in] | runner | The test runner managing this suite. |
| [in] | callable | A generic callable object, usually a lambda, invoked when the suite executes. Its first parameter must be suite&. |
| [in] | arguments | A possibly empty list of arguments forwarded to the callable after the leading suite& reference. |
Delegates to runnable, which binds the callable with its arguments. After construction, the suite is registered with the static test runner.
Definition at line 371 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::runnable< suite >::runnable(), suite(), micro_os_plus::micro_test_plus::detail::runnable< suite >::name(), and micro_os_plus::micro_test_plus::detail::runnable< suite >::runner().
Referenced by micro_os_plus::micro_test_plus::static_suite::static_suite(), suite(), suite(), suite(), micro_os_plus::micro_test_plus::top_suite::top_suite(), operator=(), and operator=().
|
delete |
References suite().
|
delete |
References suite().
|
overridevirtual |
No resources are owned directly by suite; the destructor performs no explicit clean-up. If tracing is enabled, the suite name is output for diagnostic purposes.
Definition at line 336 of file test.cpp.
References micro_os_plus::micro_test_plus::detail::runnable< suite >::name_.
|
inherited |
| sl | The source location from which the abort is triggered. |
Delegates immediately to runner_.abort(), passing the supplied source location so that the error message identifies the call site before the process is terminated via ::abort().
Definition at line 369 of file test.cpp.
|
protectedinherited |
| child_test | Owning pointer to the newly created subtest. |
| suite | The parent suite to which execution results are reported. |
Transfers ownership of child_test into children_subtests_ and immediately invokes subtest::run() on the newly stored subtest. The parent's executed-subtest counter is then incremented. The child's check counters are intentionally not merged into the parent totals; each subtest reports only its own counters. The child's totals are, however, accumulated into suite so that the suite summary reflects all checks performed by its subtests.
Definition at line 394 of file test.cpp.
Referenced by micro_os_plus::micro_test_plus::suite::test().
|
inlinenodiscardnoexceptinherited |
Returns the number of child subtests owned by this node.
Definition at line 349 of file test-inlines.h.
|
inlinenodiscardnoexceptinherited |
Returns the sequential index of the most recently created child subtest.
Definition at line 329 of file test-inlines.h.
|
inlinenoexceptinherited |
Each call to test() invokes this method before constructing the new subtest, so the index values form a strictly increasing, one-based sequence.
Definition at line 339 of file test-inlines.h.
Referenced by micro_os_plus::micro_test_plus::suite::test().
|
inlinenodiscardnoexceptinherited |
Returns a pointer to the null-terminated name stored in name_.
Definition at line 194 of file test-inlines.h.
Referenced by micro_os_plus::micro_test_plus::static_suite::static_suite(), micro_os_plus::micro_test_plus::suite::suite(), micro_os_plus::micro_test_plus::suite::operator=(), and micro_os_plus::micro_test_plus::suite::test().
References suite().
References suite(), micro_os_plus::micro_test_plus::detail::runnable< suite >::name(), run(), test(), and timings().
|
inlinenodiscardnoexceptinherited |
Returns the one-based positional index of this object within its parent.
Definition at line 305 of file test-inlines.h.
Referenced by micro_os_plus::micro_test_plus::top_suite::top_suite(), micro_os_plus::micro_test_plus::top_suite::name(), and micro_os_plus::micro_test_plus::suite::test().
|
inlinenoexceptinherited |
| index | The new index value. |
Sets the positional index of this object within its parent.
Definition at line 319 of file test-inlines.h.
|
nodiscardnoexceptinherited |
Delegates immediately to runner_.reporter(), returning the reporter associated with the owning runner instance.
Definition at line 359 of file test.cpp.
Referenced by micro_os_plus::micro_test_plus::static_suite::run().
|
overridevirtual |
Invokes the stored callable with the Self_T instance, surrounded by reporter calls to begin and end the suite.
Implements micro_os_plus::micro_test_plus::detail::runnable< suite >.
Reimplemented in micro_os_plus::micro_test_plus::static_suite.
Definition at line 359 of file test.cpp.
Referenced by operator=().
|
inlinenodiscardnoexceptinherited |
Returns a reference to the owning test runner.
Definition at line 380 of file test-inlines.h.
Referenced by micro_os_plus::micro_test_plus::suite::suite(), and micro_os_plus::micro_test_plus::suite::test().
| void micro_os_plus::micro_test_plus::suite::test | ( | const char * | name, |
| Callable_T && | callable, | ||
| Args_T &&... | arguments ) |
| Callable_T | The type of a callable object. |
| Args_T | The types of the callable arguments. |
| [in] | name | The test case name or description, used in reports. |
| [in] | callable | A generic callable object, usually a lambda, invoked to perform the test. |
| [in] | arguments | A possibly empty list of arguments to be passed to the callable. |
The test function template registers and executes a test case within the µTest++ framework. It accepts a descriptive name, a callable object (such as a lambda or function pointer), and an optional list of arguments to be passed to the callable. The test case is reported using the provided name, and its execution is managed by the framework's test runner.
Each test case typically involves evaluating a logical expression, such as comparing a computed result to an expected value. For C++ projects, it is also possible to verify whether evaluating an expression throws exceptions. Each test either succeeds or fails, and for expectations, the test runner maintains counts of successful and failed checks.
This function template enables flexible and expressive test case definitions, supporting both parameterised and non-parameterised tests. It is typically invoked at global scope or within test suite definitions to ensure automatic registration and execution.
A test case is characterised by a name, a function that performs the checks, and optionally, arguments to be passed to that function. The implementation of test invokes the provided function with the given arguments and reports the results to the test runner.
Definition at line 437 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::runnable< suite >::after_subtest_create_(), micro_os_plus::micro_test_plus::detail::runnable< suite >::increment_subtest_index(), micro_os_plus::micro_test_plus::detail::runnable< suite >::name(), micro_os_plus::micro_test_plus::detail::runnable< suite >::own_index(), and micro_os_plus::micro_test_plus::detail::runnable< suite >::runner().
Referenced by operator=().
|
inlinenodiscardnoexcept |
Returns a const reference to the timestamps member.
Definition at line 477 of file test-inlines.h.
References timings_.
|
inlinenodiscardnoexcept |
Returns a reference to the timestamps member.
Definition at line 467 of file test-inlines.h.
References timings_.
Referenced by micro_os_plus::micro_test_plus::reporter_human::end_suite(), micro_os_plus::micro_test_plus::reporter_tap::end_suite(), operator=(), and micro_os_plus::micro_test_plus::static_suite::run().
|
inlinenodiscardnoexceptinherited |
Returns a const reference to the runner_totals member.
Definition at line 215 of file test-inlines.h.
|
inlinenodiscardnoexceptinherited |
Returns a reference to the runner_totals member.
Definition at line 205 of file test-inlines.h.
|
protectedinherited |
Definition at line 512 of file test.h.
Referenced by micro_os_plus::micro_test_plus::top_suite::name().
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
Definition at line 224 of file test.h.
Referenced by micro_os_plus::micro_test_plus::static_suite::~static_suite(), micro_os_plus::micro_test_plus::suite::~suite(), micro_os_plus::micro_test_plus::top_suite::~top_suite(), micro_os_plus::micro_test_plus::top_suite::name(), and micro_os_plus::micro_test_plus::static_suite::run().
|
protectedinherited |
Definition at line 406 of file test.h.
Referenced by micro_os_plus::micro_test_plus::static_suite::static_suite().
|
protectedinherited |
|
protected |
|
protectedinherited |