The CppUTest test framework works well on most platforms with Approval Tests.
This section describes the various ways of using Approval Tests with CppUTest.
Note: Approval Tests has some specific build requirements if it is built with the Ninja build generator. If you use Ninja with Approval Tests, special care is needed when setting up builds, to avoid compilation errors or test failures. If you have any problems with this, please see Troubleshooting Misconfigured Build.
Note: This integration is not tested on CygWin. The CppUTest integration with Approval Tests does not build on this platform, CygWin, therefore our tests of it are disabled.
Note: Approval Tests's use of STL objects triggers test failures from CppUTest's memory-leak checking, and so our integration with CppUTest currently turns of its memory leak checks.
Approval Tests requires that the following are found:
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/TestPlugin.h>
#include <CppUTest/TestRegistry.h>Approval Tests is tested with CppUTest v4.0.
We haven't yet provided a Starter Project for using Approval Tests with CppUTest.
This is partly based on the assumption that anyone already using CppUTest will have their own project set up, and anyone else would probably use Catch2 instead.
If it would be helpful for us to such a Starter Project, please let us know, via the contact details in Contributing to ApprovalTests.cpp.
Create a file main.cpp and add just the following two lines:
#define APPROVALS_CPPUTEST
#include "ApprovalTests.hpp"If you have an existing CppUTest-based test program that provides its own main(), you won't be able to use the
approach above.
Instead, you should make the following additions to your own source file that contains main().
// main.cpp:
// 1. Add these two lines to your main:
#define APPROVALS_CPPUTEST_EXISTING_MAIN
#include "ApprovalTests.hpp"
int main(int argc, char** argv)
{
// 2. Add this line to your main:
ApprovalTests::initializeApprovalTestsForCppUTest();
int result = CommandLineTestRunner::RunAllTests(argc, argv);
TestRegistry::getCurrentRegistry()->resetPlugins();
return result;
}