Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation on how to create C++-level unit tests #1172

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions testsuite/cpptests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# C++ unit tests

This directory contains C++-level unit tests. The tests are run using the
Boost.Test framework, and are compiled into a separate executable,
`run_all_cpptests` by CMake if NEST is configured with Boost.

Tests are written in header files, preferably one file per test suite. Each
header file must include the Boost.Test header, create a test suite and at
least one test. Validation of predicate values is done with the
`BOOST_REQUIRE()` macro.

A small example of a test suite header can look like this:

```cpp
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( foo_suite )

BOOST_AUTO_TEST_CASE( foo_case )
{
int i = 1;

BOOST_REQUIRE( i > 0 ); // passes
BOOST_REQUIRE( i == 2 ); // fails
}

BOOST_AUTO_TEST_SUITE_END()
```

The header then has to be included in `run_all.cpp` to be included in the
executable.

For further documentation on using the Boost.Test framework, see the [Boost.Test
documentation](https://www.boost.org/doc/libs/1_69_0/libs/test/doc/html/index.html).