Skip to content

optiks/ApprovalTests.Net

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ApprovalTests

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

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

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

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:

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

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

Will Produce a File

SampleTest.TestList.received.txt
[0] = Dan
[1] = James
[2] = Jason
[3] = Katrina
[4] = Llewellyn

Simply rename this to SampleTest.TestList.approved.txt and the test will now pass.

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.

Backers

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

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

About

ApprovalTest verification library for .Net

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.9%
  • Other 0.1%