autofixture - AutoFixture 5.0.0-preview0005

AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.

PM> Install-Package AutoFixture -Version 5.0.0-preview0005 -Source https://www.myget.org/F/autofixture/api/v3/index.json

Copy to clipboard

> nuget.exe install AutoFixture -Version 5.0.0-preview0005 -Source https://www.myget.org/F/autofixture/api/v3/index.json

Copy to clipboard

> dotnet add package AutoFixture --version 5.0.0-preview0005 --source https://www.myget.org/F/autofixture/api/v3/index.json

Copy to clipboard
<PackageReference Include="AutoFixture" Version="5.0.0-preview0005" />
Copy to clipboard
source https://www.myget.org/F/autofixture/api/v3/index.json

nuget AutoFixture  ~> 5.0.0-preview0005
Copy to clipboard

> choco install AutoFixture --version 5.0.0-preview0005 --source https://www.myget.org/F/autofixture/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "autofixture" -SourceLocation "https://www.myget.org/F/autofixture/api/v2"
Install-Module -Name "AutoFixture" -RequiredVersion "5.0.0-preview0005" -Repository "autofixture" -AllowPreRelease
Copy to clipboard

Browse the sources in this package using Visual Studio or WinDbg by configuring the following symbol server URL: https://www.myget.org/F/autofixture/api/v2/symbolpackage/


AutoFixture

License release NuGet version NuGet preview version NuGet downloads AutoFixture

Write maintainable unit tests, faster.

AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case.

Check the testimonials to see what other people have to say about AutoFixture.

Table of Contents

Overview

(Jump straight to the CheatSheet if you just want to see some code samples right away.)

AutoFixture is designed to make Test-Driven Development more productive and unit tests more refactoring-safe. It does so by removing the need for hand-coding anonymous variables as part of a test's Fixture Setup phase. Among other features, it offers a generic implementation of the Test Data Builder pattern.

When writing unit tests, you typically need to create some objects that represent the initial state of the test. Often, an API will force you to specify much more data than you really care about, so you frequently end up creating objects that has no influence on the test, simply to make the code compile.

AutoFixture can help by creating such Anonymous Variables for you. Here's a simple example:

[Fact]
public void IntroductoryTest()
{
    // Arrange
    Fixture fixture = new Fixture();

    int expectedNumber = fixture.Create<int>();
    MyClass sut = fixture.Create<MyClass>();
    // Act
    int result = sut.Echo(expectedNumber);
    // Assert
    Assert.Equal(expectedNumber, result);
}

This example illustrates the basic principle of AutoFixture: It can create values of virtually any type without the need for you to explicitly define which values should be used. The number expectedNumber is created by a call to Create<T> - this will create a 'nice', regular integer value, saving you the effort of explicitly coming up with one.

The example also illustrates how AutoFixture can be used as a SUT Factory that creates the actual System Under Test (the MyClass instance).

Given the right combination of unit testing framework and extensions for AutoFixture, we can further reduce the above test to be even more declarative:

xUnit

[Theory, AutoData]
public void IntroductoryTest(int expectedNumber, MyClass sut)
{
    int result = sut.Echo(expectedNumber);
    Assert.Equal(expectedNumber, result);
}

NUnit

[Test, AutoData]
public void IntroductoryTest(int expectedNumber, MyClass sut)
{
    int result = sut.Echo(expectedNumber);
    Assert.Equal(expectedNumber, result);
}

Notice how we can reduce unit tests to state only the relevant parts of the test. The rest (variables, Fixture object) is relegated to attributes and parameter values that are supplied automatically by AutoFixture. The test is now only two lines of code.

Using AutoFixture is as easy as referencing the library and creating a new instance of the Fixture class!

Downloads

AutoFixture packages are distributed via NuGet.
To install the packages you can use the integrated package manager of your IDE, the .NET CLI, or reference the package directly in your project file.

dotnet add package AutoFixture --version 4.18.0
<PackageReference Include="AutoFixture" Version="4.18.0" />

AutoFixture offers a variety of utility packages and integrations with most of the major mocking libraries and testing frameworks.

Core packages

The core packages offer the full set of AutoFixture's features without requring any testing framework or third party integration.

Product Package Stable Preview Downloads
The core package AutoFixture NuGet NuGet NuGet
Assertion idioms AutoFixture.Idioms NuGet NuGet NuGet
Seed extensions AutoFixture.SeedExtensions NuGet NuGet NuGet

Mocking libraries

AutoFixture offers integations with most major .NET mocking libraries.
These integrations enable such features as configuring mocks, auto-injecting mocks, etc.

Product Package Stable Preview Downloads
Moq AutoFixture.AutoMoq NuGet NuGet NuGet
NSubstitute AutoFixture.AutoNSubstitute NuGet NuGet NuGet
FakeItEasy AutoFixture.AutoFakeItEasy NuGet NuGet NuGet
Rhino Mocks AutoFixture.AutoRhinoMocks NuGet NuGet NuGet

NOTE: Since AutoFixture tries maintain compatibility with a large number of package versions, the packages bundled with AutoFixture might not contain the latest features of your mocking library.
Make sure to install the latest version of the mocking library package, alongside the AutoFixture package.

Testing frameworks

AutoFixture offers integrations with most major .NET testing frameworks.
These integrations enable auto-generation of test cases, combining auto-generated data with inline arguments, etc.

Product Package Stable Preview Downloads
xUnit v3 AutoFixture.Xunit3 NuGet NuGet NuGet
xUnit v2 AutoFixture.Xunit2 NuGet NuGet NuGet
xUnit v1 AutoFixture.Xunit NuGet NuGet NuGet
NUnit v4 AutoFixture.NUnit4 NuGet NuGet NuGet
NUnit v3 AutoFixture.NUnit3 NuGet NuGet NuGet
NUnit v2 AutoFixture.NUnit2 NuGet NuGet NuGet
Foq AutoFixture.AutoFoq NuGet NuGet NuGet

You can check the compatibility with your target framework version on the wiki or on the NuGet website.

vNext feed

The artifacts of the next major version are published to nuget.org, and are marked with the preview suffix (e.g. 5.0.0-preview00007).
You can use these packages to early access and test the next major version of the AutoFixture.
Make sure to enable the preview packages in your IDE in order to see the latest version.

NOTE: This preview versions exists for the preview purpose only, so use them with caution:

  • New versions of packages might contain breaking changes and API could change drastically from package to package. By other words, we don't follow the SemVer policy for the packages in this feed;
  • Preview packages might be unlisted over time, in order to not clutter the version suggestion dialog in IDEs, but will generally remain available

Documentation

Additional resources

Feedback & Questions

If you have questions, feel free to ask. The best places to ask are:

License

AutoFixture is Open Source software and is released under the MIT license.
The licenses allows the use of AutoFixture libraries in free and commercial applications and libraries without restrictions.

.NET Foundation

This project is supported by the .NET Foundation.

  • .NETFramework 4.6.1
    • Fare (>= 2.1.1 && < 3.0.0)
    • Microsoft.Bcl.AsyncInterfaces (>= 1.0.0)
    • Microsoft.Bcl.HashCode (>= 1.0.0)
  • .NETStandard 2.0
    • Fare (>= 2.1.1 && < 3.0.0)
    • Microsoft.Bcl.AsyncInterfaces (>= 1.0.0)
    • Microsoft.Bcl.HashCode (>= 1.0.0)
    • System.ComponentModel.Annotations (>= 4.3.0)
  • .NETStandard 2.1
    • Fare (>= 2.1.1 && < 3.0.0)
    • System.ComponentModel.Annotations (>= 4.3.0)
  • .NETFramework 4.6.1: 4.6.1.0
  • .NETStandard 2.0: 2.0.0.0
  • .NETStandard 2.1: 2.1.0.0

Owners

Oleks Povar AutoFixture

Authors

Mark Seemann, AutoFixture

Project URL

https://github.com/AutoFixture/AutoFixture

License

MIT

Info

6106 total downloads
80 downloads for version 5.0.0-preview0005
Download (412.13 KB)
Download symbols (152.67 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
5.0.0-preview0005 412.13 KB Tue, 10 May 2022 20:36:13 GMT 80
5.0.0-preview0004 412.23 KB Thu, 24 Mar 2022 20:53:56 GMT 83
5.0.0-preview0003 672.71 KB Mon, 08 Nov 2021 21:45:13 GMT 74
4.0.0-alpha.281 493.33 KB Tue, 17 Oct 2017 19:09:10 GMT 83
4.0.0-alpha.280 493.37 KB Mon, 16 Oct 2017 21:51:44 GMT 75
4.0.0-alpha.277 493.03 KB Mon, 16 Oct 2017 20:56:59 GMT 73
4.0.0-alpha.276 493.14 KB Mon, 16 Oct 2017 20:48:27 GMT 82
4.0.0-alpha.275 494.92 KB Mon, 16 Oct 2017 10:39:27 GMT 84
4.0.0-alpha.274 498.48 KB Mon, 16 Oct 2017 10:00:54 GMT 85
4.0.0-alpha.273 498.47 KB Mon, 16 Oct 2017 09:14:51 GMT 88
4.0.0-alpha.272 498.22 KB Sun, 15 Oct 2017 12:48:10 GMT 74
4.0.0-alpha.271 498.43 KB Sun, 15 Oct 2017 11:48:44 GMT 80
4.0.0-alpha.270 498.21 KB Sat, 14 Oct 2017 20:46:34 GMT 76
4.0.0-alpha.269 498.05 KB Fri, 13 Oct 2017 09:27:45 GMT 83
4.0.0-alpha.268 498.49 KB Fri, 13 Oct 2017 08:13:43 GMT 71
4.0.0-alpha.267 498.42 KB Fri, 13 Oct 2017 07:58:41 GMT 78
4.0.0-alpha.266 498.15 KB Thu, 12 Oct 2017 12:48:38 GMT 71
4.0.0-alpha.265 498.41 KB Wed, 11 Oct 2017 11:49:25 GMT 77
4.0.0-alpha.263 497.73 KB Tue, 10 Oct 2017 20:34:08 GMT 75
4.0.0-alpha.262 497.97 KB Tue, 10 Oct 2017 17:21:08 GMT 97
4.0.0-alpha.261 498.85 KB Tue, 10 Oct 2017 13:35:35 GMT 83
4.0.0-alpha.260 498.07 KB Mon, 09 Oct 2017 08:57:05 GMT 74
4.0.0-alpha.259 498.41 KB Mon, 09 Oct 2017 08:49:47 GMT 100
4.0.0-alpha.258 498.44 KB Sun, 08 Oct 2017 21:32:18 GMT 75
4.0.0-alpha.257 498.1 KB Sun, 08 Oct 2017 16:09:50 GMT 70
4.0.0-alpha.256 498.32 KB Sun, 08 Oct 2017 13:38:24 GMT 76
4.0.0-alpha.255 500.55 KB Sat, 07 Oct 2017 23:33:22 GMT 74
4.0.0-alpha.254 500.49 KB Sat, 07 Oct 2017 23:09:32 GMT 64
4.0.0-alpha.253 500.24 KB Fri, 06 Oct 2017 09:23:23 GMT 78
4.0.0-alpha.252 500.55 KB Fri, 06 Oct 2017 08:56:58 GMT 66
4.0.0-alpha.251 500.84 KB Fri, 06 Oct 2017 08:03:41 GMT 77
4.0.0-alpha.250 500.66 KB Fri, 06 Oct 2017 07:56:45 GMT 59
4.0.0-alpha.249 499.93 KB Wed, 04 Oct 2017 09:25:49 GMT 67
4.0.0-alpha.248 500.08 KB Tue, 03 Oct 2017 11:57:30 GMT 72
4.0.0-alpha.247 500.02 KB Tue, 03 Oct 2017 10:51:03 GMT 70
4.0.0-alpha.246 499.91 KB Tue, 03 Oct 2017 10:44:18 GMT 73
4.0.0-alpha.245 499.94 KB Tue, 03 Oct 2017 10:36:55 GMT 86
4.0.0-alpha.244 500.02 KB Mon, 02 Oct 2017 10:54:22 GMT 74
4.0.0-alpha.243 500.46 KB Mon, 02 Oct 2017 09:33:26 GMT 97
4.0.0-alpha.242 297.83 KB Sun, 01 Oct 2017 18:39:13 GMT 87
4.0.0-alpha.241 297.7 KB Sat, 30 Sep 2017 21:00:28 GMT 74
4.0.0-alpha.240 297.69 KB Sat, 30 Sep 2017 20:42:14 GMT 88
4.0.0-alpha.238 296.68 KB Thu, 21 Sep 2017 16:33:07 GMT 84
4.0.0-alpha.237 296.67 KB Thu, 21 Sep 2017 08:51:45 GMT 63
4.0.0-alpha.236 296.65 KB Wed, 20 Sep 2017 19:13:11 GMT 66
4.0.0-alpha.235 296.68 KB Tue, 19 Sep 2017 13:23:23 GMT 78
4.0.0-alpha.234 296.65 KB Tue, 19 Sep 2017 09:07:56 GMT 77
4.0.0-alpha.233 296.66 KB Mon, 18 Sep 2017 10:13:33 GMT 78
4.0.0-alpha.232 296.65 KB Mon, 18 Sep 2017 09:30:28 GMT 70
4.0.0-alpha.231 296.72 KB Mon, 18 Sep 2017 09:19:33 GMT 71
4.0.0-alpha.230 296.71 KB Thu, 14 Sep 2017 07:25:32 GMT 68
4.0.0-alpha.229 296.73 KB Wed, 13 Sep 2017 12:24:04 GMT 83
4.0.0-alpha.228 296.72 KB Tue, 12 Sep 2017 11:35:07 GMT 76
4.0.0-alpha.227 296.61 KB Tue, 12 Sep 2017 08:28:47 GMT 62
4.0.0-alpha.226 296.59 KB Mon, 11 Sep 2017 08:23:43 GMT 66
4.0.0-alpha.225 296.59 KB Mon, 11 Sep 2017 08:17:33 GMT 78
4.0.0-alpha.224 296.6 KB Mon, 11 Sep 2017 08:11:43 GMT 68
4.0.0-alpha.223 296.58 KB Fri, 08 Sep 2017 08:48:30 GMT 73
4.0.0-alpha.222 296.68 KB Thu, 07 Sep 2017 08:07:18 GMT 71
4.0.0-alpha.221 296.68 KB Wed, 06 Sep 2017 13:08:38 GMT 69
4.0.0-alpha.220 296.68 KB Wed, 06 Sep 2017 12:28:47 GMT 64
4.0.0-alpha.219 296.67 KB Wed, 06 Sep 2017 09:33:07 GMT 88
4.0.0-alpha.218 296.67 KB Tue, 05 Sep 2017 09:09:05 GMT 65
4.0.0-alpha.217 296.67 KB Tue, 05 Sep 2017 08:54:01 GMT 91
4.0.0-alpha.216 296.67 KB Fri, 01 Sep 2017 10:56:01 GMT 73
4.0.0-alpha.215 296.68 KB Fri, 01 Sep 2017 08:57:01 GMT 77
4.0.0-alpha.214 296.69 KB Thu, 31 Aug 2017 11:13:55 GMT 73
4.0.0-alpha.213 296.68 KB Thu, 31 Aug 2017 10:53:30 GMT 68
4.0.0-alpha.212 296.67 KB Thu, 31 Aug 2017 10:05:42 GMT 75
4.0.0-alpha.211 296.68 KB Thu, 31 Aug 2017 09:29:35 GMT 71
4.0.0-alpha.210 296.67 KB Tue, 29 Aug 2017 10:13:36 GMT 87
4.0.0-alpha.209 296.68 KB Mon, 28 Aug 2017 08:44:15 GMT 76
4.0.0-alpha.208 296.6 KB Thu, 24 Aug 2017 22:50:26 GMT 77
4.0.0-alpha.207 296.59 KB Thu, 24 Aug 2017 22:41:26 GMT 75
4.0.0-alpha.206 296.6 KB Thu, 24 Aug 2017 09:51:48 GMT 74
4.0.0-alpha.205 296.61 KB Tue, 22 Aug 2017 09:44:03 GMT 84
4.0.0-alpha.204 296.54 KB Tue, 22 Aug 2017 09:00:06 GMT 87
4.0.0-alpha.203 296.54 KB Tue, 22 Aug 2017 08:49:02 GMT 78
4.0.0-alpha.202 149.8 KB Sun, 20 Aug 2017 07:14:57 GMT 72
4.0.0-alpha.201 149.8 KB Fri, 18 Aug 2017 11:24:51 GMT 77