Home

Awesome

<!-- 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="https://avatars3.githubusercontent.com/u/36907" height="30px"> ApprovalTests

Build status License NuGet Status Backers on Open Collective Sponsors on Open Collective

This project is not being actively maintained. Instead consider using Verify. See Migrating from ApprovalTests for more information.

Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid unit testing.

See Milestones for release notes.

It is compatible with most .Net unit testing frameworks (Nunit, MsTest, xUnit, MBUnit)

<!-- toc -->

Contents

What can it be used for?

Approval Tests can be used for verifying objects that require more than a simple assert. They also come prepackaged with utilities for some common .Net scenarios including:

Video Tutorials

You can watch a bunch of short videos on getting started and using ApprovalTests in .Net at YouTube

Podcasts

If you prefer auditory learning, you might enjoy the following podcast

Docs

Available on NuGet

Install-Package ApprovalTests

Examples

Verifying a List

<!-- snippet: sample_test -->

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

[UseReporter(typeof(VisualStudioReporter))]
[TestFixture]
public class SampleTest
{
    [Test]
    public void TestList()
    {
        var names = new[] {"Llewellyn", "James", "Dan", "Jason", "Katrina"};
        Array.Sort(names);
        Approvals.VerifyAll(names, label: "");
    }
}

<sup><a href='/src/ApprovalTests.Tests/SampleTest.cs#L1-L15' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_test' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Will Produce a File

`SampleTest.TestList.received.txt`
<!-- snippet: SampleTest.TestList.approved.txt -->

<a id='snippet-SampleTest.TestList.approved.txt'></a>

[0] = Dan
[1] = James
[2] = Jason
[3] = Katrina
[4] = Llewellyn

<sup><a href='/src/ApprovalTests.Tests/SampleTest.TestList.approved.txt#L1-L5' title='Snippet source file'>snippet source</a> | <a href='#snippet-SampleTest.TestList.approved.txt' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

It will also open these 2 files (.received. & .approved. ) in a diff editor.

<img src="docs/images/sample_test_01_open_diff.png" width="50%" height="50%">

You can approve these results by copying everything (ctrl+a, ctrl+c) and pasting it in the right hand side (ctrl+a, ctrl+v)

<img src="docs/images/sample_test_02_approving.png" width="50%" height="50%">

In most situations, you will use one of the supported DiffTools to examine and approve the result.

Alternatively, you can rename the .received. file to SampleTest.TestList.approved.txt and the test will now pass.

note: The diff tools are NOT opened when the tests pass, only on failure.

Approved File Artifacts

The *.approved.* files must be checked into source your source control. ApprovalTests now ignores line endings by default (so you can remove *.approved.* binary from your .gitattributes file if you added previously).

If you would like to verify line endings, simply add [assembly: IgnoreLineEndingsAttribute(false)] to your AssemblyInfo.cs

Do not add *.received.* files to your source control (they are transitory, and some SCMs like TFS will lock them or mark them read-only, which will break every dependent test).

More Info

Questions?

ask on twitter: @LlewellynFalco or #ApprovalTests

Credits

Contributors

This project exists thanks to all the people who contribute.

<a href="graphs/contributors"><img src="https://opencollective.com/approvals/contributors.svg?width=890&button=false" /></a>

Backers

Thank you to all our backers! 🙏 [Become a backer]

<a href="https://opencollective.com/approvals#backers" target="_blank"><img src="https://opencollective.com/approvals/backers.svg?width=890"></a>

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor] <a href="https://opencollective.com/approvals/sponsor/0/website" target="_blank"><img src="https://opencollective.com/approvals/sponsor/0/avatar.svg"></a>