A modern C++-20 unit-testing framework.
Many unit-testing frameworks have been released so far. Yet none combines the following qualities:
- Macro free: expression introspection without macros, leverages modern C++-20, easy to discover.
- Parallel: executes any number of tests simultaneously, utilizes all CPU cores, reliably reports failures.
- Production ready: easy to integrate as CMake library without dependencies, JUnit reports, UTF-8 support, flexible runtime configuration.
Further details are elaborated in the official documentation.
Let's start with a basic example:
Consider a standard sum
function together with three tests to ensure its correctness.
#include <clean-test/clean-test.h>
constexpr auto sum(auto... vs) { return (0 + ... + vs); }
namespace ct = clean_test;
using namespace ct::literals;
auto const suite = ct::Suite{"sum", [] {
"0"_test = [] { ct::expect(sum() == 0_i); };
"3"_test = [] { ct::expect(sum(1, 2) == 1 + 2_i); };
"A"_test = [] { ct::expect(sum(-1) < 0_i and sum(+1) > 0_i); };
}};
Since sum
is correctly implemented, all tests will succeed.
But what would happen if we made a mistake and wrote
constexpr auto sum(auto... vs) { return (10 + ... + vs); }
instead?
Failure in ../test/Demo.cpp:12
( 10 == 0 )
Failure in ../test/Demo.cpp:13
( 13 == ( 1 + 2 ) )
Failure in ../test/Demo.cpp:14
( ( 9 < 0 ) and <unknown> )
Clean Test shows how different parts of an ct::expect
-ation are evaluated.
This works for constants, temporaries and even short circuiting operators alike.
The user-defined literals from namespace clean_test::literals
can be used to support this introspection
but are not mandatory.
By default Clean Test utilizes all available hardware threads to execute tests in parallel. Failure detection and reporting are thread-safe - even if your tests are parallel themselves.
All aspects of test execution can be configured dynamically. It is possible to specify at runtime which test cases should be selected, how they should be executed and what kind of reporting is desired. Clean Test ensures valid UTF-8 reports and thus can safely be utilized in your CI-pipelines.
Details about Clean Test were presented at Meeting C++ 2022 in Berlin:
Clean Test already provides all core features, but currently still lacks some convenience functionality. There is a list of envisioned features that will be added in the coming weeks and months.
Clean Test consists of 100% standard C++-20 and works with any modern compiler toolchain. It works with gcc (version 10 and above) and Clang (version 11 and above) on Linux as well as with MSVC (version 19.29 and above) on Windows.