Skip to main content

The Initialisation & Exit Reference

Functions for initialising the framework and returning an exit code. More...

Functions Index

intexit_code (void)

Complete the test run and return the exit code. More...

voidinitialize (int argc, char *argv[], const char *name="Main")

Initialise the µTest++ framework. More...

Description

Functions for initialising the framework and returning an exit code.

These functions are responsible for initialising the test runner and returning the test result as the process exit code. Proper initialisation ensures that the µTest++ framework is correctly configured to manage and execute test cases, while the exit code reflects the overall outcome of the tests, supporting integration with automated build and continuous integration systems.

The simplest test consists of a single test case containing 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 this test is executed, the output is as follows:

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

Functions

exit_code()

int micro_os_plus::micro_test_plus::exit_code (void)
nodiscard

Complete the test run and return the exit code.

Parameters

None.

Returns

0 if all tests were successful, 1 if any test failed.

In addition to the test cases defined in main(), additional test suites may be declared as static objects either within the same file or in other files, and are automatically registered via the static constructors mechanism.

The exit_code function finalises the execution of all registered test suites and test cases within the µTest++ framework, and returns an appropriate exit code to the operating system. This function should be called at the end of the test program, typically from the main() function, to ensure that all results are properly reported and the correct status is communicated.

The returned value indicates the overall success or failure of the test run, allowing integration with build systems and continuous integration environments.

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

initialize()

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

Initialise the µTest++ framework.

Parameters
[in] argcThe number of command-line arguments.
[in] argvArray of pointers to null-terminated argument strings.
[in] nameThe name of the default test suite. Defaults to "Main" if not specified.
Returns

Nothing.

The initialize function sets up the µTest++ testing framework, preparing it for test execution. It processes command-line arguments, configures the test environment, and establishes the default test suite name. This function should be called at the beginning of the test programme, typically from the main() function, to ensure proper initialisation of all framework components.

The provided arguments may be used to configure verbosity or other run-time options for the test session.

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


Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.