Macro-free, expressive checks
Checks are plain C++20 expressions, such as t.expect (mt::eq (a, 42)), written without C macros. A failed check reports the file, the line, and the actual values of the operands. Test suites are static objects that register themselves, so adding a new suite requires no changes to existing code.
Built for bare-metal
The framework does not use iostream, so its small footprint suits microcontrollers with limited memory. Results are written to stdout, so semihosting or a serial port is sufficient. The same tests run on Cortex-M, Cortex-A, and RISC-V devices, on QEMU, and on native macOS, Windows and GNU/Linux hosts.
Standard TAP output
Results use the TAP 14 format by default, so standard TAP tools and CI pipelines can process them. Use --reporter=human for readable console output, and --output-file to also save the results to a file. The overall outcome is returned as the process exit code.
A first test
The outputs below were produced by running the program with --verbose; the header lines, the timings, and the totals were omitted.
#include "micro-os-plus/micro-test-plus.h"
// Define a shortcut for the namespace.
namespace mt = micro_os_plus::micro_test_plus;
// Create the test runner.
mt::runner tr;
int
main (int argc, char* argv[])
{
// Initialise the runner with command line arguments.
tr.initialise (argc, argv);
// Add the top suite and get a reference to it.
auto& ts = tr.add_top_suite ();
// Add a test case to the top suite; its body runs immediately.
ts.test ("Check truth", [] (auto& t)
{
// Check that 6 times 7 equals 42.
t.expect (mt::eq (6 * 7, 42)) << "the answer is 42";
});
// Run the registered suites, if any, and return the test result.
return tr.run_suites ();
}
TAP version 14
# Subtest: minimal-test
# Subtest: Check truth
ok 1 - the answer is 42
1..1
ok 1 - Check truth # { passed, 1 check }
1..1
ok 1 - minimal-test # { passed, 1 check in 1 test case }
1..1
µTest++ human-readable report
• minimal-test
• Check truth
✓ the answer is 42
✓ Check truth - passed (1 check)
✓ minimal-test - passed (1 check in 1 test case)