SkillAgentSearch skills...

Verify

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

Install / Use

/learn @VerifyTests/Verify
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<!-- GENERATED FILE - DO NOT EDIT This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets). Source File: /readme.source.md To change this file edit the source file and then run MarkdownSnippets. -->

<img src='/src/icon.png' height='30px'> Verify

Discussions Build status NuGet Status NuGet 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.<!-- include: intro. path: /docs/mdsource/intro.include.md -->

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.<!-- endInclude -->

See Milestones for release notes.

Sponsors

Entity Framework Extensions<!-- include: sponsors. path: /docs/mdsource/sponsors.include.md -->

Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.

Entity Framework Extensions

Developed using JetBrains IDEs

JetBrains logo.

TestMu AI

<p style="font-size:21px; color:black;">Browser testing via<br> <a href="https://www.testmuai.com/?utm_medium=sponsor&utm_source=verify" target="_blank"> <img src="docs/TestMu.png" style="vertical-align: middle;" width="500" /> </a> </p><!-- endInclude -->

Requirements

  • Supported runtimes: net462, net472, net48, net481, net6, net8, net9, and net10.
  • Supported SDK: 9.0.301 and up

Getting started wizard

Get customized instructions for the specific combination of Operating System, IDE, Test Framework, and Build Server.

Start wizard.

NuGet

  • https://nuget.org/packages/Verify.NUnit/
  • https://nuget.org/packages/Verify.XunitV3/
  • https://nuget.org/packages/Verify.Fixie/
  • https://nuget.org/packages/Verify.Expecto/
  • https://nuget.org/packages/Verify.MSTest/
  • https://nuget.org/packages/Verify.TUnit/

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

ImplicitUsings

All examples use Implicit Usings. Ensure <ImplicitUsings> is set to enable to ensure examples compile correctly.<!-- include: implicit-usings. path: /docs/mdsource/implicit-usings.include.md -->

<ImplicitUsings>enable</ImplicitUsings>

If ImplicitUsings are not enabled, substitute usages of Verify() with Verifier.Verify().<!-- endInclude -->

Class being tested

Given a class to be tested:

<!-- snippet: ClassBeingTested -->

<a id='snippet-ClassBeingTested'></a>

public static class ClassBeingTested
{
    public static Person FindPerson() =>
        new()
        {
            Id = new("ebced679-45d3-4653-8791-3d969c4a986c"),
            Title = Title.Mr,
            GivenNames = "John",
            FamilyName = "Smith",
            Spouse = "Jill",
            Children =
            [
                "Sam",
                "Mary"
            ],
            Address = new()
            {
                Street = "4 Puddle Lane",
                Country = "USA"
            }
        };
}

<sup><a href='/src/TargetLibrary/ClassBeingTested.cs#L1-L26' title='Snippet source file'>snippet source</a> | <a href='#snippet-ClassBeingTested' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

NUnit

Support for NUnit

<!-- snippet: SampleTestNUnit -->

<a id='snippet-SampleTestNUnit'></a>

[TestFixture]
public class Sample
{
    [Test]
    public Task Test()
    {
        var person = ClassBeingTested.FindPerson();
        return Verify(person);
    }
}

<sup><a href='/src/Verify.NUnit.Tests/Snippets/Sample.cs#L1-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-SampleTestNUnit' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

xUnitV3

Support for xUnitV3

<!-- snippet: SampleTestXunitV3 -->

<a id='snippet-SampleTestXunitV3'></a>

public class Sample
{
    [Fact]
    public Task Test()
    {
        var person = ClassBeingTested.FindPerson();
        return Verify(person);
    }
}

<sup><a href='/src/Verify.XunitV3.Tests/Snippets/Sample.cs#L1-L13' title='Snippet source file'>snippet source</a> | <a href='#snippet-SampleTestXunitV3' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Fixie

Support for Fixie

<!-- snippet: SampleTestFixie -->

<a id='snippet-SampleTestFixie'></a>

public class Sample
{
    public Task Test()
    {
        var person = ClassBeingTested.FindPerson();
        return Verify(person);
    }
}

<sup><a href='/src/Verify.Fixie.Tests/Snippets/Sample.cs#L1-L12' title='Snippet source file'>snippet source</a> | <a href='#snippet-SampleTestFixie' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Fixie is less opinionated than other test frameworks. As such it leaves up to the consumer how to configure test execution.<!-- include: fixie-convention. path: /docs/mdsource/fixie-convention.include.md -->

To enable Verify the ITestProject and IExecution interfaces need to be used.

Requirements:

  • Assign the target assembly in ITestProject.Configure using VerifierSettings.AssignTargetAssembly
  • Wrap test executions in IExecution.Run using ExecutionState.Set

An example implementation of the above:

<!-- snippet: TestProject.cs -->

<a id='snippet-TestProject.cs'></a>

public class TestProject :
    ITestProject,
    IExecution
{
    public void Configure(TestConfiguration configuration, TestEnvironment environment)
    {
        VerifierSettings.AssignTargetAssembly(environment.Assembly);
        configuration.Conventions.Add<DefaultDiscovery, TestProject>();
    }

    public async Task Run(TestSuite testSuite)
    {
        foreach (var testClass in testSuite.TestClasses)
        {
            foreach (var test in testClass.Tests)
            {
                if (test.HasParameters)
                {
                    foreach (var parameters in test
                                 .GetAll<TestCase>()
                                 .Select(_ => _.Parameters))
                    {
                        using (ExecutionState.Set(testClass, test, parameters))
                        {
                            await test.Run(parameters);
                        }
                    }
                }
                else
                {
                    using (ExecutionState.Set(testClass, test, null))
                    {
                        await test.Run();
                    }
                }
            }
        }
    }
}

<sup><a href='/src/Verify.Fixie.Tests/FixieSetup/TestProject.cs#L1-L39' title='Snippet source file'>snippet source</a> | <a href='#snippet-TestProject.cs' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet --> <!-- endInclude -->

Expecto

Support for Expecto

<!-- snippet: SampleTestExpecto -->

<a id

View on GitHub
GitHub Stars3.4k
CategoryDevelopment
Updated5h ago
Forks180

Languages

C#

Security Score

100/100

Audited on Mar 28, 2026

No findings