All Projects → VerifyTests → Verify

VerifyTests / Verify

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

Projects that are alternatives of or similar to Verify

Snapshooter
Snapshooter is a snapshot testing tool for .NET Core and .NET Framework
Stars: ✭ 118 (-43.81%)
Mutual labels:  snapshot, snapshot-testing
Cupaloy
Simple Go snapshot testing
Stars: ✭ 131 (-37.62%)
Mutual labels:  snapshot, snapshot-testing
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (-34.29%)
Mutual labels:  snapshot, snapshot-testing
reducer-tester
Utilities for testing redux reducers
Stars: ✭ 19 (-90.95%)
Mutual labels:  snapshot-testing, snapshot
Playbook Ios
📘A library for isolated developing UI components and automatically taking snapshots of them.
Stars: ✭ 830 (+295.24%)
Mutual labels:  snapshot, snapshot-testing
Snapshot Diff
Diffing snapshot utility for Jest
Stars: ✭ 490 (+133.33%)
Mutual labels:  snapshot, snapshot-testing
pytest-snapshot
A plugin for snapshot testing with pytest.
Stars: ✭ 68 (-67.62%)
Mutual labels:  snapshot-testing, snapshot
Syrupy
🥞 The sweeter pytest snapshot plugin
Stars: ✭ 73 (-65.24%)
Mutual labels:  snapshot, snapshot-testing
Typescript Snapshots Plugin
Snapshots language service support for Typescript
Stars: ✭ 122 (-41.9%)
Mutual labels:  snapshot, snapshot-testing
Kubicorn
kubicorn is a free and open source project that solves the Kubernetes infrastructure problem and gives users a rich golang library to work with infrastructure.
Stars: ✭ 1,671 (+695.71%)
Mutual labels:  snapshot
Approvaltests.java
ApprovalTest verification library for Java
Stars: ✭ 160 (-23.81%)
Mutual labels:  snapshot-testing
Backy2
backy2: Deduplicating block based backup software for ceph/rbd, image files and devices
Stars: ✭ 126 (-40%)
Mutual labels:  snapshot
Swift Snapshot Testing
📸 Delightful Swift snapshot testing.
Stars: ✭ 2,347 (+1017.62%)
Mutual labels:  snapshot-testing
Cv4pve Autosnap
Automatic snapshot tool for Proxmox VE
Stars: ✭ 123 (-41.43%)
Mutual labels:  snapshot
Snap Shot
Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
Stars: ✭ 170 (-19.05%)
Mutual labels:  snapshot
Report Designer
🚀 打印设计、可视化、大屏、编辑器、设计器、数据分析、报表设计、组件化、表单设计、h5页面、调查问卷、pdf生成、流程图、试卷、SVG、图形元素、物联网
Stars: ✭ 160 (-23.81%)
Mutual labels:  snapshot
Save Page State
A chrome extension to save the state of a page for further analysis
Stars: ✭ 208 (-0.95%)
Mutual labels:  snapshot
Knoxite
A data storage & backup system
Stars: ✭ 165 (-21.43%)
Mutual labels:  snapshot
React Native Testing Example
Example of unit testing a React Native & Redux app using Jest (and Snapshots!)
Stars: ✭ 159 (-24.29%)
Mutual labels:  snapshot
Grub Btrfs
Include btrfs snapshots at boot options. (Grub menu)
Stars: ✭ 153 (-27.14%)
Mutual labels:  snapshot

Verify

Discussions Build 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.

Support is available via a Tidelift Subscription.


Part of the .NET Foundation

Contents

NuGet packages

Usage

Class being tested

Given a class to be tested:

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

snippet source | anchor

xUnit

Support for xUnit

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

snippet source | anchor

NUnit

Support for NUnit

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

snippet source | anchor

MSTest

Support for MSTest

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

snippet source | anchor

Initial Verification

When the test is initially run will fail with:

First verification. Sample.Test.verified.txt not found.
Verification command has been copied to the clipboard.

The clipboard will contain the following:

cmd /c move /Y "C:\Code\Sample\Sample.Test.received.txt" "C:\Code\Sample\Sample.Test.verified.txt"

Notes:

If a Diff Tool is detected it will display the diff:

InitialDiff

To verify the result:

  • Execute the command from the clipboard, or
  • Use the diff tool to accept the changes, or
  • Manually copy the text to the new file

Verified result

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

{
  GivenNames: John,
  FamilyName: Smith,
  Spouse: Jill,
  Address: {
    Street: 4 Puddle Lane,
    Country: USA
  },
  Children: [
    Sam,
    Mary
  ],
  Id: Guid_1
}

snippet source | anchor

Subsequent Verification

If the implementation of ClassBeingTested changes:

public static class ClassBeingTested
{
    public static Person FindPerson()
    {
        return new()
        {
            Id = new("ebced679-45d3-4653-8791-3d969c4a986c"),
            Title = Title.Mr,
            // Middle name added
            GivenNames = "John James",
            FamilyName = "Smith",
            Spouse = "Jill",
            Children = new()
            {
                "Sam",
                "Mary"
            },
            Address = new()
            {
                // Address changed
                Street = "64 Barnett Street",
                Country = "USA"
            }
        };
    }
}

snippet source | anchor

And the test is re run it will fail with

Verification command has been copied to the clipboard.
Assert.Equal() Failure
                                  ↓ (pos 21)
Expected: ···\n  GivenNames: 'John',\n  FamilyName: 'Smith',\n  Spouse: 'Jill···
Actual:   ···\n  GivenNames: 'John James',\n  FamilyName: 'Smith',\n  Spouse:···
                                  ↑ (pos 21)

The clipboard will again contain the following:

cmd /c move /Y "C:\Code\Sample\Sample.Test.received.txt" "C:\Code\Sample\Sample.Test.verified.txt"

See also: Clipboard

The Diff Tool is 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.

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:

using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using VerifyTests;
using VerifyXunit;
using Xunit;

[UsesVerify]
public class StaticSettings
{
    [Fact]
    public Task Test()
    {
        return Verifier.Verify("String to verify");
    }
}

public static class StaticSettingsUsage
{
    [ModuleInitializer]
    public static void Initialize()
    {
        VerifierSettings.AddScrubber(_ => _.Replace("String to verify", "new value"));
    }
}

//Only required if using a legacy version of .net
#if(!NET5_0)
namespace System.Runtime.CompilerServices
{
    [AttributeUsage(AttributeTargets.Method, Inherited = false)]
    public sealed class ModuleInitializerAttribute :
        Attribute
    {
    }
}
#endif

snippet source | anchor

Videos

Extensions

More Documentation

Alternatives

Projects/tools that may be a better alternative to Verify

Security contact information

To report a security vulnerability, use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Icon

Helmet designed by Leonidas Ikonomou from The Noun Project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].