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

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

Functions

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.
 

Detailed Description

Test cases are named sequences of checks.

Test cases group several checks to be executed in the same environment.

There can be any number of test cases, and each test case is performed by invoking a function, parametrised with a name/description, a callable (usually a lambda), and optional arguments.

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";
});

Function Documentation

◆ 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.

A test case is a sequence of test conditions (or simply tests, or checks), which are expectations/assumptions, i.e. conditions expected to be true.

Tests are based on logical expressions, which usually compute a result and compare it to an expected value. For C++ projects, it is also possible to check if, while evaluating an expression, exceptions are thrown or not. Each test either succeeds or fails. For expectations, the runner keeps counts of successful and failed tests.

A test case has a name, a function which performs the checks, and possibly arguments.

The test_case implementation invokes the function with the provided arguments, and reports the results.

Example
mt::test_case ("Check answer with comparator", [] {
mt::expect (mt::eq (compute_answer (), 42)) << "answer is 42";
});
Template Parameters
Callable_TThe type of an object that can be called.
Args_TThe type of the callable arguments.
Parameters
[in]nameThe test case name or description. A short string used in the report.
[in]callableA generic callable object, invoked to perform the test. Usually a lambda.
[in]argumentsA possibly empty list of arguments to be passed to the callable.
Returns
Nothing.

Definition at line 87 of file inlines.h.