2025
tUnit: a predicate-based C++ test framework
A C++17 test framework where assertions are composable predicates, with scoped exception traces and JUnit XML output. Tests itself in CI.
tUnit starts from one idea: a test should read like a specification. An assertion is Test::assert(description, lhs, predicate, rhs), where the predicate is a stateless functor from a small library: is_equal, is_in_range, contains_element, is_sorted, is_prime, and so on. Predicates compose through combinators such as and_, implies, exactly_n_of, and conditional, so a compound expectation is one expression, not a chain of macros.
How it works
An Evaluator<T, U, P> holds the two operands and the predicate and evaluates on call. Every assertion is logged to an Orchestrator singleton that tracks suites, tests, and assertions, parses command-line filters, prints the summary, and writes JUnit XML for CI dashboards. TUNIT_TRACE_FUNCTION() and TUNIT_SCOPED_TRACE(msg) attach a scope trail to any exception that escapes a test, so a failure deep in a helper still names the path that reached it.
The umbrella header tUnit.h pulls in about fifteen headers and four translation units, so "single header" describes the include experience, not the layout. Compile-time assertions are on the to-do list and the constexpr path is disabled for now.
Scale
Twenty-six commits over five days, nine self-test files, a CMake workflow in GitHub Actions, and a committed results.xml from the framework testing itself.