AnCH unit tests library is unit tests library which provides utility class and functions to generate unit tests.
AnCH unit tests depends on anch-cli library to parse unit tests executable.
CMake target anch::ut:
See installation.
AnCH unit tests library provides main function which will execute the following calls:
anch::ut::UnitTests::initialize anch::ut::UnitTests::beforeTest anch::ut::UnitTests::add anch::ut::UnitTests::afterTest anch::ut::UnitTests::uninitialize These functions can be registered with the following signature std::function<void()> and can throw exceptions which will be caught by the library.
When initialization fails, tests and uninitialization are not run. A failed uninitialization fails the unit tests.
Tests are run in registration order (or in command line order with -t ).
To register tests, function anch::ut::setup(anch::ut::UnitTests&) has to be declared.
Unit tests name and description can be registered in this function with name and description anch::ut::UnitTests methods.
It will make executable with help argument (-h or --help for help): -l or --list-tests to list registered unit test, -t or --test followed by the test name to run a specific test and nothing to run all tests.
anch::ut::assertThat function is based on std::format function with {} paceholders: the message has to be a string literal, and it is checked at compile time against the arguments (literal braces are written {{ and }} ). Failed assertions (assertThat , assertTrue , assertFalse and fail ) report their file and line.
A failed assertion in a thread other than the test one terminates the process: wrap thread functions with anch::ut::ThreadErrors::wrap (ut/threadErrors.hpp ) and call anch::ut::ThreadErrors::rethrow once threads have been joined.
Colors are disabled when output is not a terminal or when NO_COLOR environment variable is set.
Unit tests suite (tests exception , assert and assert-format fail on purpose):