ApprovalTests Features

December 9, 2022 ยท View on GitHub

Contents

Approvals.AssertText

Watch a Video demo of this feature

If you prefer not to store your expectations in the .approved. files, you can store them directly in-line with your code. Sample:

(Before):

var header = new Header();
var actual = header.MakeHeading("I am ten chars");
var expected = "";
Approvals.AssertText(expected, actual);

snippet source | anchor

When you do this, it will copy the c# for the .received. to your clipboard, so you can paste it in-line.

(After)

var header = new Header();
var actual = header.MakeHeading("I am ten chars");
var expected = new[]{
    "**************",
    "I am ten chars",
    "**************",

};
Approvals.AssertText(expected, actual);

snippet source | anchor

Currently, it put the text as an array of strings that gets concatenated as this tends to read better.

It will also write the results to a temp files on failure and open a DiffTool, so you can easily view the results and differences.

MachineSpecificReporter

ApprovalsFilename

Sometimes you want to parse an approvals filename to get the parts.

var approvalsFilename = ApprovalsFilename.Parse(@"..\Email\EmailTest.Testname.Microsoft_Windows_10_Education.approved.eml");

snippet source | anchor

Will produce

GetFullPath: ..\Email\EmailTest.Testname.Microsoft_Windows_10_Education.approved.eml
Directory: ..\Email
ClassName: EmailTest
MethodName: Testname
AdditionalInformation: [Microsoft_Windows_10_Education]
ApprovedStatus: approved
Extension: eml

snippet source | anchor

Making Custom Reporters

Environment SpecificTests


Back to User Guide