Skip to main content

The Test Cases Reference

Test cases are named sequences of checks. More...

Functions Index

voidtest_case (const char *name, Callable_T &&callable, Args_T &&... arguments)

Define and execute a test case. More...

Description

Test cases are named sequences of checks.

Test cases in µTest++ are named collections of checks that are executed within the same environment. Each test case is defined by providing a descriptive name and a callable object (typically a lambda), along with any optional arguments required for the test.

Test cases enable developers to organise related checks together, improving the clarity and maintainability of the test suite. Any number of test cases may be defined, each focusing on a specific aspect of the code under test.

By grouping checks in this way, it becomes easier to identify which functionality is being verified and to interpret the results in the context of the overall software quality.

Examples
 
 mt::test_case ("Check various conditions", [] {
  mt::expect (mt::eq (compute_answer (), 42)) << "answer eq 42";
  mt::expect (mt::ne (compute_answer (), 43)) << "answer ne 43";
 });
 
 mt::test_case ("Check various conditions with operators", [] {
  using namespace mt::operators;
  using namespace mt::literals;
 
  mt::expect (compute_answer () == 42_i) << "answer == 42";
  mt::expect (compute_answer () != 43_i) << "answer != 43";
 });

Functions

test_case()

template <typename Callable_T, typename... Args_T>
void micro_os_plus::micro_test_plus::test_case (const char * name, Callable_T && callable, Args_T &&... arguments)

Define and execute a test case.

Template Parameters
Callable_TThe type of the callable object to be executed as the test case.
Args_TThe types of the arguments to be passed to the callable.
Parameters
[in] nameThe test case name or description, used in test reports.
[in] callableA generic callable object, usually a lambda, invoked to perform the test.
[in] argumentsA possibly empty list of arguments to be passed to the callable.
Returns

Nothing.

The test_case 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_case invokes the provided function with the given arguments and reports the results to the test runner.

Example
 
 mt::test_case ("Check answer with comparator", [] {
  mt::expect (mt::eq (compute_answer (), 42)) << "answer is 42";
 });

Definition at line 114 of file micro-test-plus-inlines.h.


Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.