The [Boost].UT test framework works well with Approval Tests.
[Boost].UT is a single header/single module, macro-free μ(micro)/Unit Testing Framework that requires C++17 / C++20
Approval Tests for [Boost].UT requires that a file called ut.hpp
is found.
Approval Tests needs [Boost].UT version b970a20 or above.
Add the following two lines to your source code:
#define APPROVALS_UT
#include "ApprovalTests.hpp"
Below is an example of a call to an approval test inside a [Boost].UT test:
"ItCanVerifyAFile"_test = []() {
Approvals::verify("Approval Tests can verify text via the golden master method");
};
In the following example, two instances of ApprovalTests are called inside the same test. We need to use sections with different names, to prevent Approval Tests from using the same output file for both tests:
"ItCanUseMultipleVerify"_test = []() {
{
// Here we simulate test sections, so that Approval Tests uses different
// output file names for the different verify() calls.
auto section = NamerFactory::appendToOutputFilename("section 1");
Approvals::verify("Approval Tests can verify text via the golden master method");
}
{
auto section = NamerFactory::appendToOutputFilename("section 2");
Approvals::verify("Approval Tests can verify different text via the golden master method");
}
};