GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ApprovalTests.cpp/doc/Overview.md at master · approvals/ApprovalTests.cpp

Expand file tree

/

Overview.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
74 lines (56 loc) · 2.96 KB
/

Overview.md

Copy path

File metadata and controls

74 lines (56 loc) · 2.96 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Overview of Approval Tests

Contents

  • Summary
  • Traditional Asserts
  • Approval Tests

Summary

Approval Tests are an alternative to writing expression assertions in your code.

As the following examples demonstrate, Approval Tests can result in significantly simpler and more elegant tests of complex objects.

Traditional Asserts

Traditional tests spend equal time focusing on creating the inputs and verifying the outputs.

When the objects being tested are non-trivial, either the tests become quite verbose (as shown in this example), or it's tempting to only test a small part of the behaviour.

// Arrange, Act
Sandwich s = createSandwichForTest();
// Assert
REQUIRE("Sourdough" == s.getBread());
REQUIRE(s.getCondiments().contains("Mayo"));
REQUIRE(s.getCondiments().contains("Pepper"));
REQUIRE(s.getCondiments().contains("Olive Oil"));
REQUIRE(s.getFillings().contains("Tomato"));
REQUIRE(s.getFillings().contains("Lettuce"));
REQUIRE(s.getFillings().contains("Cheddar"));

snippet source | anchor

Approval Tests

Approval Tests simplify the verification of outputs. They do this by writing the outputs to a file, which once saved, becomes your spec.

You still supply the inputs, but Approval Tests gives you powerful ways of viewing complex outputs, meaning you can move on to the next feature or next test more quickly.

// Arrange, Act
Sandwich s = createSandwichForTest();
// Assert
ApprovalTests::Approvals::verify(s);

snippet source | anchor

This generates the approval file - which is generated for you, but approved by you.

sandwich {
    bread: "Sourdough",
    condiments: ["Mayo", "Pepper", "Olive Oil"],
    fillings: ["Tomato", "Lettuce", "Cheddar"]
}

snippet source | anchor


Back to User Guide

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.