ApprovalTests.cpp

C++ snapshot testing library supporting multiple test frameworks with extensive documentation

What it is

ApprovalTests.cpp is a C++ implementation of approval testing, also known as golden master testing or snapshot testing. This approach provides an alternative to traditional assertions by capturing and comparing complex output against approved reference files. The library excels at testing objects with numerous fields, collections of objects, and other scenarios where conventional unit assertions become unwieldy.

The library integrates with major C++ test frameworks including Boost.Test, Catch2, CppUTest, doctest, Google Test, and [Boost].ut. Documentation covers getting started tutorials, framework-specific setup guides, and advanced topics such as custom reporters, comparators, writers, namers, and scrubbers for handling non-deterministic output. Build system integration is documented for CMake, Conan, and vcpkg.

Developers can learn approval testing concepts through structured guides covering single object testing, container testing, combination testing, and exception testing. The documentation emphasizes good practices for string conversions and designing effective approval strings. Extensive customization points allow teams to tailor the library to their specific workflows and reporting preferences.

The project is open source and hosted on GitHub with continuous integration support documented for common build machines and CI servers. A growing C++ reference section provides API documentation for core classes, approval functions, and scrubber utilities. The site is built with Sphinx and hosted on Read the Docs, offering versioned documentation and PDF downloads.

This description was generated by AI from the site's public content and may contain errors.

What you can do there

  • Learn approval testing concepts and C++ implementation
  • Integrate with six major C++ test frameworks
  • Customize reporters, comparators, and scrubbers
  • Configure build systems with CMake, Conan, or vcpkg
  • Access API reference for core classes and functions

Who it's for

C++ developers seeking snapshot testing alternatives for complex object validation

Frequently asked questions about approvaltestscpp.readthedocs.io

›What is approval testing and how does it differ from traditional unit testing

Approval testing captures actual output and compares it against approved reference files instead of using explicit assertions. It is especially useful for complex objects where writing detailed assertions would be impractical.

›Which C++ test frameworks are supported by ApprovalTests.cpp

The library supports Boost.Test, Catch2, CppUTest, doctest, Google Test, and [Boost].ut with documentation for each integration.

›How do I handle non-deterministic output like timestamps or memory addresses in approval tests

Scrubbers can be configured to normalize or remove non-deterministic parts of output before comparison, allowing stable approval files.

›Can I use custom reporters for viewing test differences

Yes, the library supports custom reporters and provides guidance on selecting reporters via environment variables or submitting new reporters.

›Is ApprovalTests.cpp compatible with CMake and package managers

Documentation covers CMake integration as well as Conan and vcpkg package manager support for dependency management.

›Where can I find the source code and contribute to ApprovalTests.cpp

The source code is available on GitHub where contributions are welcome, with documentation on contributing, coding patterns, and maintaining documentation.