How to Test the Contents of a Container

When to test a container

You have called a method that returns a collection of objects, and you want a nicer read-out than the standard verify() will give you.


  1. Copy this starter text.

std::vector<std::string> objectsToVerify{"hello", "world"};
ApprovalTests::Approvals::verifyAll("TITLE", objectsToVerify);

(See snippet source)

which would produce:


[0] = hello
[1] = world

(See snippet source)

  1. Replace the objectsToVerify container with your collection of objects.

  2. Change the TITLE to something meaningful

  3. Run it, and approve the output.

More Examples

For some examples, see VectorTests.cpp.

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.