Skip to content

Latest commit

 

History

History
231 lines (137 loc) · 11.9 KB

readme.source.md

File metadata and controls

231 lines (137 loc) · 11.9 KB

Verify

Discussions Build status NuGet Status NuGet Status NuGet Status NuGet Status NuGet Status

Verify is a snapshot tool that simplifies the assertion of complex data models and documents.

Verify is called on the test result during the assertion phase. It serializes that result and stores it in a file that matches the test name. On the next test execution, the result is again serialized and compared to the existing file. The test will fail if the two snapshots do not match: either the change is unexpected, or the reference snapshot needs to be updated to the new result.

NuGet packages

Snapshot management

Accepting or declining a snapshot file is part of the core workflow of Verify. There are several ways to do this and the approach(s) selected is a personal preference.

Usage

All examples use ImplicitUsings. Ensure the following is set to have examples compile correctly <ImplicitUsings>enable</ImplicitUsings>

Class being tested

Given a class to be tested:

snippet: ClassBeingTested

xUnit

Support for xUnit

snippet: SampleTestXunit

NUnit

Support for NUnit

snippet: SampleTestNUnit

Expecto

Support for Expecto

snippet: SampleTestExpecto

Caveats

Due to the nature of the Expecto implementation, the following APIs in Verify are not supported.

  • settings.UseTypeName()
  • settings.UseMethodName()
  • settings.UseParameters()
  • settings.UseTextForParameters()

Instead use a custom name parameter.

MSTest

Support for MSTest

snippet: SampleTestMSTest

Initial Verification

When the test is initially run will fail. If a Diff Tool is detected it will display the diff.

InitialDiff

To verify the result:

Verified result

This will result in the Sample.Test.verified.txt being created:

snippet: Verify.Xunit.Tests/Snippets/Sample.Test.verified.txt

Subsequent Verification

If the implementation of ClassBeingTested changes:

snippet: ClassBeingTestedChanged

And the test is re run it will fail.

The Diff Tool will display the diff:

SecondDiff

The same approach can be used to verify the results and the change to Sample.Test.verified.txt is committed to source control along with the change to ClassBeingTested.

VerifyJson

VerifyJson performs the following actions

  • Convert to JToken (if necessary).
  • Apply ignore member by name for keys.
  • PrettyPrint the resulting text.

snippet: VerifyJson

Results in:

snippet: SerializationTests.VerifyJsonString.verified.txt

Received and Verified

  • All *.verified.* files should be committed to source control.
  • All *.received.* files should be excluded from source control.

Static settings

Most settings are available at the both global level and at the instance level.

When modifying settings at the both global level it should be done using a Module Initializer:

snippet: StaticSettings.cs

Versioning

Verify follows Semantic Versioning. The same applies for extensions to Verify. Small changes in the resulting snapshot files may be deployed in a minor version. As such nuget updates to Verify.* should be done as follows:

  • Updates all Verify.*packages in isolation
  • Re-run all tests.
  • If there are changes, ensure they look correct given the release notes. If the changes do not look correct, raise an issue.
  • Accept those changes.

Snapshot changes do not trigger a major version change to avoid causing Diamond dependency issues for downstream extensions.

Media

Extensions

More Documentation

include: doc-index

Alternatives

Projects/tools that may be a better alternative to Verify

Icon

Helmet designed by Leonidas Ikonomou from The Noun Project.