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.
Steps
Copy this starter text.
std::vector<std::string> objectsToVerify{"hello", "world"};
ApprovalTests::Approvals::verifyAll("TITLE", objectsToVerify);
(See snippet source)
which would produce:
TITLE
[0] = hello
[1] = world
(See snippet source)
Replace the
objectsToVerify
container with your collection of objects.Change the TITLE to something meaningful
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.