How to Test a Variety of Values for One Input

When to use Approvals::verifyAll()

When you want to test a lot of variations for a single input value.

If you have more than parameter that you want to vary, check out Testing Combinations.


  1. Copy this starter text.

    std::vector<std::string> inputs{"input.value1", "input.value2"};
    ApprovalTests::Approvals::verifyAll("TITLE", inputs, [](auto input, auto& stream) {
        stream << input << " => "
               << "placeholder";

(See snippet source)

  1. Modify the input container for your chosen values.

  2. Run it, and make sure that you have your inputs wired up correctly.

If they are wired up correctly, you will see a file that looks like this: it is the left hand side of the file that matters at this point: all combinations of your own input values should be listed:


input.value1 => placeholder
input.value2 => placeholder

(See snippet source)

  1. Replace the “placeholder” with a call to the functionality that you want to test.

  2. Change the TITLE to something meaningful

  3. Run it, and approve the output.

Further Advice

For advice on effective formatting, see Tips for Designing Strings. As you write out larger volumes of data in your approval files, experience has shown that the choice of layout of text in approval files can make a big difference to maintainability of tests, when failures occur.