Utlitity classes

The cmdline_test_runner_factory class

The cmdline_test_runner_factory class i a convenience class in order to build a test runner from command line arguments. It is intended to simplify test application creation when one wants some control from the command line as how the test application executes.

Using this class, the following options will be available on the command line.

-c, --console=<FORMAT>
 Console output; FORMAT is ‘none’, ‘summary’, ‘suite-summary’, ‘total-summary’, or ‘detailed’ (default)
-h, --help Print this text and exit.
-l, --log=<FILE[,FORMAT]>
 Log result to file FILE. See option -c for valid values on FORMAT
-n, --no-count Disable fail count. Program will always return 0.
class cmdline_test_runner_factory
get_test_runner()
// test_runner get_test_runner(int, const char **)

The input to this method is typically argc and argv from the main() function.

// Assuming that my_1_suite and my_2_suite classes are test suites
// defined elsewhere, a complete test application with the above mentioned
// capabilities my look like this.

int main(int argc, const char **argv) {
  cmdline_test_runner_factory factory;
  test_runner tester = factory.get_test_runner(argc, argv);
  int failCount = 0;

  tester.stage<my_1_suite>();
  tester.stage<my_2_suite>();

  failCount = tester.run_all();

  return failCount;
}