OverviewΒΆ

There are five basic elements:

  • Verify function
  • test
  • test_suite
  • test_runner
  • test_reporter

The Verify() function is the core of all tests. This is the function which performs the actual verification that a specific constraint on some value is met.

Tests are organized in test suites. Test suites are classes, and tests are methods in those classes. Data that the tests act upon are either variables locally defined in the method or data members of the suite.

Test data may be initialized either in the suite_setup() method, or in the test_setup() method depending on if it should be initialized once per suite or before each test. There are also a corresponging suite_teardown() and test_teardown() methods to perform cleanup upon completion of each suite or test. A suite is completed once all tests in it have been executed.

Tests in test suites are executed by a test runner. All test suites that are to be executed need to registered with the test runner.

The test runner will report the result of each executed test to the test reporter which is responsible for the output to the user. It is simple task to implement a test reporter if the ones available does not provide the desired output. The default reporter is a text reporter that outputs the report to a given ostream, the default is cout.

Please note that there is no auto-registration of tests with a test runner. Hence, tests or rather test suites need to be regsisterd with a runner in order to be executed. This may be considered an anti-feature by some, but it makes it very clear which tests are run. There is no need to look in a makefile to decide if a certain test is linked in or not.

It also makes it trivial to run tests in parallell. Just create a set of test runners, register different suites with each one and run them in different threads.

If auto-registration is an absolute necessity for you, chek out another package. Thera are a lot of nice ones around. But be aware, what may look like auto-registration in the first place may require instantiation of some class or some other construct for each suite, in which case wide::unittest will work equaly well. wide::unittest requires one function call per suite to execute.