Skip to content

Latest commit

 

History

History
95 lines (69 loc) · 3.67 KB

EnvironmentSpecificTests.md

File metadata and controls

95 lines (69 loc) · 3.67 KB

Contents

EnvironmentSpecificTest

Sometimes you need Additional Information in the Approval Output File Name.

ApprovalTests allows for ClassName.MethodName.AdditionalInforamtion.approved.extension

using(var cleanup = NamerFactory.AsEnvironmentSpecificTest(()=> "Any.Additional.Data"))
{
}

As this will clean up the additional information regardless of the test execution.

There are a few convenience functions in ApprovalResults setup for the common situations:

  • UniqueForDotNetVersion
  • UniqueForMachineName
  • UniqueForOs
  • UniqueForRuntime
  • GetUserName

MachineSpecificReporter

Some things will always be different if you run them on Windows 7 versus Windows 10 (for example: WinForms will always render differently). Approval Test has a feature to handle this situation by including the OS in approvals file name so you have a different approval file for each OS.

If you are using a machine specific name in your approval tests for example:

using (ApprovalResults.UniqueForOs())
{
    Approvals.Verify("Data");
}

snippet source | anchor

This can produce files such as:

Like EmailTest.Testname.Microsoft_Windows_10_Education.approved.eml

EmailTest.Testname.Microsoft_Windows_10_Enterprise.approved.eml
EmailTest.Testname.Microsoft_Windows_10_Home_N.approved.eml
EmailTest.Testname.Microsoft_Windows_10_Pro.approved.eml
EmailTest.Testname.Microsoft_Windows_11_Enterprise.approved.eml
EmailTest.Testname.Microsoft_Windows_11_Pro.approved.eml
EmailTest.Testname.Microsoft_Windows_Server_2016_Datacenter.approved.eml
EmailTest.Testname.Microsoft_Windows_Server_2019_Datacenter.approved.eml

snippet source | anchor

If this is run on a new machine, it could produce a new approval file. This can be confusing as you might not remember what the old system used to produce.

[UseReporter(typeof(MachineSpecificReporter))]

snippet source | anchor

If you use a MachineSpecificReporter and the existing approval file does not exist (or is empty), it will search or the last approved version from a different machine and copy it over as a starting point. This will always start with a line:

Copied from: EmailTest.Testname.Microsoft_Windows_10_Pro.approved.eml

This makes it easier to understand how this system differs from the last system.


Back to User Guide