Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Data-driven test cases

Datasets
Declaring and registering test cases with datasets
Operations on dataset
Joins
Zips
Grid (Cartesian products)
Datasets generators
Why data-driven test cases?

Some tests are required to be repeated for a series of different input parameters. One way to achieve this is manually register a test case for each parameter. You can also invoke a test function with all parameters manually from within your test case, like this:

void single_test( int i )
{
  BOOST_TEST( /* test assertion */ );
}

void combined_test()
{
  int params[] = { 1, 2, 3, 4, 5 };
  std::for_each( params, params+5, &single_test );
}

The approach above has several drawbacks:

Parameter generation, scalability and composition

In some circumstance, one would like to run a parametrized test over an arbitrary large set of values. Enumerating the parameters by hand is not a solution that scales well, especially when these parameters can be described in another function that generates these values. However, this solution has also limitations

Data driven tests in the Boost.Test framework

The facilities provided by the Unit Test Framework addressed the issues described above:

The remainder of this section covers the notions and feature provided by the Unit Test Framework about the data-driven test cases, in particular:

  1. the notion of dataset and sample is introduced
  2. the declaration and registration of the data-driven test cases are explained,
  3. the operations on datasets are detailed
  4. and finally the built-in dataset generators are introduced.

PrevUpHomeNext