In some scenarios it makes sense to auto-accept any changes as part of a given test run. For example:
- Keeping a text representation of a Database schema in a
.verified.sqlfile (see Verify.SqlServer).
Note that auto accepted changes in .verified. files remain visible in source control tooling.
This can be done using AutoVerify():
var settings = new VerifySettings();
settings.AutoVerify();[Fact]
public Task AutoVerifyFluent() =>
Verify("Value")
.AutoVerify();public static class ModuleInitializer
{
[ModuleInitializer]
public static void Init() =>
VerifierSettings.AutoVerify();
}AutoVerify supports passing a delegate to control what subset of files to AutoVerify based on file path.
var settings = new VerifySettings();
settings.AutoVerify(
verifiedFile =>
Path.GetExtension(verifiedFile) == "png");[Fact]
public Task AutoVerifyFluentDelegate() =>
Verify("Value")
.AutoVerify(
verifiedFile =>
Path.GetExtension(verifiedFile) == "png");public static class ModuleInitializer
{
[ModuleInitializer]
public static void Init() =>
VerifierSettings.AutoVerify(
(typeName, methodName, verifiedFile) =>
Path.GetExtension(verifiedFile) == "png");
}By default, when AutoVerify is being used, the .verified. file will be silently replaced with no feedback to the user.
To get feedback when AutoVerify occurs, use throwException: true:
[Fact]
public Task AutoVerifyThrowException() =>
Verify("Value")
.AutoVerify(throwException: true);Using this approach the .verified. file will still be replaced, but an exception will be thrown to notify that it has occurred.
By default the same AutoVerify behavior applies both to local test runs and on the build server. To opt out of AutoVerify on the build server use includeBuildServer: false:
[Fact]
public Task AutoVerifyIncludeBuildServer() =>
Verify("Value")
.AutoVerify(includeBuildServer: false);This can be helpful when the requirement is to minimize the friction of accepting frequent local changes, but once checked in to source control then changes to any verified file should fail a test