The expected result for most approvals in an a separate .approved.
file.
Inline approvals stores the result as a string within the test source.
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
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);
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.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 tofalse
.
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.
.