|
kaycxx-test
C++ unit test framework
|
kaycxx-test separates test registration from test execution. Suite registration happens before main() starts. Test bodies run later when the test runner executes the registry.
Use the suite macro at namespace scope to define a top-level suite. It is the only macro in the test DSL and exists because ordinary function calls are not allowed at namespace scope.
The block following suite is a generated registration function. It runs during static initialization and must not be nested inside a function or another suite.
Use describe inside a suite to group related tests. Nested descriptions become part of each test's full description.
The describe callback runs immediately while the suite tree is being registered. The it callback is stored and runs later during test execution.
Suites and tests execute in declaration order.
Registration is ordinary C++ code, so loops and conditions can generate tests dynamically.
Values needed by a test must be captured by value or otherwise kept alive until the runner executes the test.
Local variables in a suite or describe registration body are destroyed when that body returns. Capturing them by reference in a test or hook produces a dangling reference because the callback runs later.
This is invalid:
Capture immutable test data by value:
For mutable state shared by hooks and tests, use static suite state or an owning object captured by value. Hooks and State describes both approaches.