Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 2.12 KB

TestContainerContents.md

File metadata and controls

58 lines (39 loc) · 2.12 KB

How to Test the Contents of a Container

Contents

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

  1. Copy this starter text.

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

snippet source | anchor

which would produce:

TITLE


[0] = hello
[1] = world

snippet source | anchor

  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.


Back to User Guide