Skip to content

Latest commit

 

History

History
53 lines (43 loc) · 2.23 KB

InlineApprovals.md

File metadata and controls

53 lines (43 loc) · 2.23 KB

How to use inline approvals

Contents

What it is

The expected result for most approvals in an a separate .approved. file. Inline approvals stores the result as a string within the test source.

Why use inline

When your result is under ten lines inline approvals has the following benefits:

  • Reduced number of test files
  • Result and test are co-located
  • Having the result visible with the code clarifies the intent of the test
  • It resembles more traditional unit tests

Solution: Use Options.inline()

Any verify() call can use inline approvals so long as the output is text. To do this simply add the option:

new Options().inline(expected);

snippet source | anchor

Workflow

On failure, approval tests will generate a temporary file of what your source code should look like if you were to approve this result and show it in the diff tool of your choice. By moving over the code you will approve the result - and change the source file.

For a more detailed explanation of the workflow see Inline Approvals Workflow

Options

Show Code

Options.inline() has two parameters:

  • The expected result
  • showCode flag (default true) If you would prefer just to see the difference between the approved and received without the surrounding Java code, set showCode to false.

Reporters

When you call .inline() whatever the current reporter is will be used to display the current code file with the generated code file on failure. If you set a reporter after this, it will override the showCode option setting it to false and only report the differences between the .approved. and .received..