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

Functions to initialise the framework and exit. More...

Functions

int micro_os_plus::micro_test_plus::exit_code (void)
 Complete the test and return the exit code.
 
void micro_os_plus::micro_test_plus::initialize (int argc, char *argv[], const char *name="Main")
 Initialize the test framework.
 

Detailed Description

Functions to initialise the framework and exit.

These are functions to initialise the test runner and to return the test result as the process exit code.

The absolute minimal test has a single test case, with a single expectation; for example:

int
main(int argc, char* argv[])
{
mt::initialize(argc, argv, "Minimal");
mt::test_case ("Check truth", [] {
mt::expect (true);
})
return mt::exit_code ();
}

When running this test, the output looks like:

• Minimal - test suite started
✓ Check truth - test case passed (1 check)
✓ Minimal - test suite passed (1 check in 1 test case)

Function Documentation

◆ exit_code()

int micro_os_plus::micro_test_plus::exit_code ( void )

Complete the test and return the exit code.

Parameters
None.
Returns
0 for success, 1 for failure.

In addition to the test cases defined in main(), there can be more separate test suites, defined as static objects in the same file or in other files, and self-registered via the static constructors mechanism.

This function triggers the execution of the globally registered test suites (if any) and returns the test result as the process exit code (0 = success).

Definition at line 78 of file micro-test-plus.cpp.

◆ initialize()

void micro_os_plus::micro_test_plus::initialize ( int argc,
char * argv[],
const char * name = "Main" )

Initialize the test framework.

Parameters
[in]argcThe number of arguments.
[in]argvArray of pointers to null terminated arguments.
[in]nameThe name of the default test suite.
Returns
Nothing.

All tests include a default test suite, which runs the test cases defined in the main function.

This function forwards the process arguments to the test framework and initialises the runner.

The name is used to identify the default test suite.

The arguments can be used to control the verbosity level.

Definition at line 57 of file micro-test-plus.cpp.