Skip to content

Latest commit

 

History

History
89 lines (58 loc) · 3.17 KB

UsingCatch.md

File metadata and controls

89 lines (58 loc) · 3.17 KB

Using Approval Tests With Catch

Contents

Getting Started With Catch 1 and 2

The Catch2 test framework works well with Approval Tests.

This section describes the various ways of using Approval Tests with Catch 2.

These steps also work with the earlier version, Catch 1, which is on the Catch 1.x branch, and is still provided for those on pre-C++11 compilers. (Please note that the Approval Tests library requires C++11 or newer, however).

Approval Tests requires that a file called catch.hpp is found.

Starter Project

The quickest way to start experimenting with Approval Tests is to:

  1. Download the project ApprovalTests.cpp.StarterProject - via the green "Clone or Download" button at the top-right of the project site.
  2. Opening the project in the C++ IDE of your choice.

Each time we release a new version of Approval Tests, we update this project, so it always has the latest features.

New Project

Create a file main.cpp and add just the following two lines:

// main.cpp:
#define APPROVALS_CATCH // This tells Approval Tests to provide a main() - only do this in one cpp file
#include "ApprovalTests.hpp"

snippet source / anchor

Existing Project - with CATCH_CONFIG_MAIN

If you have a Catch (1 or 2) project with your own main.cpp that contains the following lines, you will need to replace them with the code in the previous section.

#define CATCH_CONFIG_MAIN // remove these lines, and replace with Approval Tests lines
#include "catch.hpp"

Existing Project - with your main()

If you have supplied your own main() for Catch, you will need to teach it how to supply test names to Approval Tests.

You should make the following additions to your own source file that contains main().

// Add these two lines to the top of your main.cpp file:
#define APPROVALS_CATCH_EXISTING_MAIN
#include "ApprovalTests.hpp"

snippet source / anchor


Back to User Guide