Skip to content
Vojtech Horky edited this page May 30, 2014 · 3 revisions

Splitting the tests into more files

Often you want to keep tests in more source files but you would like to have a single binary that runs them all. That is possible with PCUT as well.

Instead of writing the PCUT_MAIN macro at the end of the source file to run the tests, use PCUT_EXPORT to export all the tests. In the main file (that is, the file with PCUT_MAIN), import these tests with PCUT_IMPORT. Short example follows.

There is no limit how many suites you want to have in a single file. In this example, each file contains just one suite.

#include <pcut/pcut.h>
PCUT_INIT
PCUT_TEST_SUITE(sums);
PCUT_TEST(add_zero) {
	PCUT_ASSERT_INT_EQUALS(42, 42 + 0);
}
/* More tests. */
PCUT_EXPORT(sum_suite);
#include <pcut/pcut.h>
PCUT_INIT
PCUT_TEST_SUITE(products);
PCUT_TEST(multiply_zero) {
	PCUT_ASSERT_INT_EQUALS(0, 42 * 0);
}
/* More tests. */
PCUT_EXPORT(product_suite);

The main file then consists of import statements only. But nothing prevents you from mixing imports with normal tests etc.

#include <pcut/pcut.h>

PCUT_INIT

PCUT_IMPORT(sum_suite);
PCUT_IMPORT(product_suite);

PCUT_MAIN()
Clone this wiki locally