Skip to content

Latest commit

 

History

History
74 lines (50 loc) · 3.09 KB

File metadata and controls

74 lines (50 loc) · 3.09 KB

Using Approval Tests With doctest

Contents

Introduction

The doctest test framework works well with Approval Tests.

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.

Doctest is similar to Catch, but claims to give faster compilation times.

Requirements

Approval Tests for doctest requires that a file called the following is found:

#include <doctest/doctest.h>

snippet source | anchor

Approval Tests needs doctest version 2.3.4 or above.

Getting Started With doctest

New Project

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

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

snippet source | anchor

Existing Project - with your main()

If you have supplied your own main() for doctest, 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_DOCTEST_EXISTING_MAIN
#include "ApprovalTests.hpp"

snippet source | anchor


Back to User Guide