AutoFixture.Xunit 4.19.0

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package AutoFixture.Xunit --version 4.19.0
                    
NuGet\Install-Package AutoFixture.Xunit -Version 4.19.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoFixture.Xunit" Version="4.19.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoFixture.Xunit" Version="4.19.0" />
                    
Directory.Packages.props
<PackageReference Include="AutoFixture.Xunit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AutoFixture.Xunit --version 4.19.0
                    
#r "nuget: AutoFixture.Xunit, 4.19.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AutoFixture.Xunit@4.19.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AutoFixture.Xunit&version=4.19.0
                    
Install as a Cake Addin
#tool nuget:?package=AutoFixture.Xunit&version=4.19.0
                    
Install as a Cake Tool

AutoFixture.xUnit

License NuGet version NuGet preview version NuGet downloads

AutoFixture.xUnit is a .NET library that integrates AutoFixture with xUnit 1.x, allowing you to effortlessly generate test data for your unit tests. By automatically populating your test parameters, it helps you write cleaner, more maintainable tests without having to manually construct test objects.

While this package is still being developed, the xUnit 1 package is deprecated.<br/> This package is intended only for legacy projects that are still using xUnit 1.x.<br/>

Table of Contents

Installation

AutoFixture packages are distributed via NuGet.<br /> 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.xUnit --version x.x.x
<PackageReference Include="AutoFixture.xUnit" Version="x.x.x" />

Getting Started

Basic Usage

AutoFixture.xUnit provides an [AutoData] attribute that automatically populates test method parameters with generated data.

For example, imagine you have a simple calculator class:

public class Calculator
{
	public int Add(int a, int b) => a + b;
}

You can write a test using AutoFixture to provide the input values:

using Xunit;
using AutoFixture.xUnit;

public class CalculatorTests
{
    [Theory, AutoData]
    public void Add_SimpleValues_ReturnsCorrectResult(
        Calculator calculator, int a, int b)
    {
        // Act
        int result = calculator.Add(a, b);

        // Assert
        Assert.AreEqual(a + b, result);
    }
}

Inline Auto-Data

You can also combine auto-generated data with inline arguments using the [InlineAutoData] attribute. This allows you to specify some parameters while still letting AutoFixture generate the rest.

using Xunit;
using AutoFixture.xUnit;
using AutoFixture;

public class CalculatorTests
{
    [Theory, InlineAutoData(5, 8)]
    public void Add_SpecificValues_ReturnsCorrectResult(
        int a, int b, Calculator calculator)
    {
        // Act
        int result = calculator.Add(a, b);

        // Assert
        Assert.AreEqual(13, result);
    }
}

Freezing Dependencies

AutoFixture's [Frozen] attribute can be used to ensure that the same instance of a dependency is injected into multiple parameters.

For example, if you have a consumer class that depends on a shared dependency:

public class Dependency { }

public class Consumer
{
    public Dependency Dependency { get; }

    public Consumer(Dependency dependency)
    {
        Dependency = dependency;
    }
}

You can freeze the Dependency so that all requests for it within the test will return the same instance:

using Xunit;
using AutoFixture.xUnit;
using AutoFixture;

public class ConsumerTests
{
    [Theory, AutoData]
    public void Consumer_UsesSameDependency(
        [Frozen] Dependency dependency, Consumer consumer)
    {
        // Assert
        Assert.AreSame(dependency, consumer.Dependency);
    }
}

Integrations

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

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 (e.g. mocking) library.<br /> Make sure to install the latest version of the integrated library package, alongside the AutoFixture packages.

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.<br/> 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

Testing frameworks

AutoFixture offers integrations with most major .NET testing frameworks.<br /> 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.

Contributing

Contributions to AutoFixture.xUnit are welcome! If you would like to contribute, please review our contributing guidelines and open an issue or pull request.

License

AutoFixture is Open Source software and is released under the MIT license.<br /> 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.

Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on AutoFixture.Xunit:

Package Downloads
Trove.Bundle.Xunit.Moq

Bundles together various packages to use xUnit and Moq.

F2F.Testing.Xunit.FakeItEasy

Brings an AutoMockFeature which initializes AutoFixture with FakeItEasy.

Treevs.Essentials.AutoFixture.Xunit

Use Xunit Theories + AutoFixture.Xunit, in a neat and concise manner.

Selkie.XUnit.Extensions

This small package contains XUnit extensions: AutoNSubstituteDataAttribute and InlineAutoNSubstituteDataAttribute.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on AutoFixture.Xunit:

Repository Stars
Glimpse/Glimpse
The open source diagnostics platform for the web
ploeh/Hyprlinkr
A URI building helper library for ASP.NET Web API
GreanTech/AtomEventStore
A server-less .NET Event Store based on the Atom syndication format
Version Downloads Last Updated
5.0.0-preview0012 1,038 1/21/2025
5.0.0-preview0011 326 4/15/2024
5.0.0-preview0010 175 3/25/2024
5.0.0-preview0009 200 3/10/2024
5.0.0-preview0008 201 2/18/2024
5.0.0-preview0007 9,848 12/9/2023
5.0.0-preview0006 180 12/4/2023
5.0.0-pdb-test0003 175 12/10/2023
5.0.0-pdb-test0002 175 12/10/2023
5.0.0-pdb-test0001 154 12/10/2023
5.0.0-dataattributes0001 215 12/27/2023
4.19.0 7,755 4/14/2025
4.18.1 57,818 11/28/2023
4.18.0 37,250 2/21/2023
4.17.0 106,510 4/20/2021
4.16.0 4,208 4/1/2021
4.15.0 28,385 12/18/2020
4.14.0 46,642 9/10/2020
4.13.0 10,673 7/9/2020
4.12.0 1,594 6/28/2020
4.11.0 73,455 7/8/2019
4.10.0 5,365 6/13/2019
4.9.0 3,248 5/28/2019
4.8.0 5,125 1/30/2019
4.7.0 1,742 1/26/2019
4.6.0 2,112 12/10/2018
4.5.1 2,031 11/25/2018
4.5.0 12,896 7/12/2018
4.4.0 2,923 5/26/2018
4.3.0 2,441 5/2/2018
4.2.1 2,654 4/16/2018
4.2.0 6,082 3/21/2018
4.1.0 2,917 2/15/2018
4.0.1 2,701 1/22/2018
4.0.0 8,515 1/10/2018
4.0.0-rc1 1,305 10/18/2017
3.51.0 55,608 10/5/2017
3.50.7 13,858 9/18/2017
3.50.6 9,751 8/16/2017
3.50.5 24,369 8/9/2017
3.50.4 2,629 8/7/2017
3.50.3 19,464 7/5/2017
3.50.2 72,525 8/31/2016
3.50.1 7,723 8/12/2016
3.50.0 5,175 8/11/2016
3.49.1 19,230 8/3/2016
3.49.0 4,036 7/5/2016
3.48.0 3,066 6/28/2016
3.47.8 6,702 6/19/2016
3.47.7 2,888 6/18/2016
3.47.6 6,225 6/13/2016
3.47.5 2,941 6/11/2016
3.47.4 10,803 6/3/2016
3.47.3 27,297 6/2/2016
3.47.2 2,735 6/2/2016
3.47.1 2,736 6/1/2016
3.47.0 2,760 5/31/2016
3.46.0 33,646 5/15/2016
3.45.3 2,757 5/12/2016
3.45.2 3,510 5/7/2016
3.45.1 3,317 4/25/2016
3.45.0 4,566 4/24/2016
3.44.1 4,534 4/20/2016
3.44.0 3,149 4/15/2016
3.43.4 2,853 4/14/2016
3.43.3 2,743 4/13/2016
3.43.2 2,845 4/12/2016
3.43.1 2,726 4/10/2016
3.43.0 4,639 3/28/2016
3.42.0 3,014 3/20/2016
3.41.1 7,137 3/13/2016
3.41.0 2,967 3/12/2016
3.40.0 8,638 2/2/2016
3.39.0 3,205 1/22/2016
3.38.1 3,019 1/3/2016
3.38.0 2,746 12/31/2015
3.37.3 3,143 12/8/2015
3.37.2 2,691 12/8/2015
3.37.1 2,727 12/3/2015
3.37.0 3,005 11/25/2015
3.36.12 4,870 11/20/2015
3.36.11 3,326 11/16/2015
3.36.9 32,723 10/21/2015
3.36.8 3,673 10/8/2015
3.36.1 2,946 10/6/2015
3.36.0 3,989 10/2/2015
3.35.1 2,970 10/2/2015
3.34.2 3,985 9/16/2015
3.34.1 2,890 9/16/2015
3.34.0 3,023 9/12/2015
3.33.0 2,963 9/5/2015
3.32.2 2,742 9/5/2015
3.32.0 2,826 9/5/2015
3.31.0 5,462 7/31/2015
3.30.8 6,571 6/17/2015
3.30.7 3,021 6/14/2015
3.30.6 3,293 6/5/2015
3.30.4 5,458 4/29/2015
3.30.3 3,885 4/19/2015
3.30.2 4,147 4/11/2015
3.30.1 8,425 4/10/2015
3.30.0 37,481 4/9/2015
3.29.0 2,858 4/9/2015
3.27.0 2,875 4/8/2015
3.25.0 2,823 4/8/2015
3.24.6 2,985 4/7/2015
3.24.5 2,848 4/6/2015
3.24.4 2,783 4/4/2015
3.24.3 6,877 3/12/2015
3.24.2 6,466 3/7/2015
3.24.1 7,636 2/28/2015
3.24.0 4,701 2/19/2015
3.23.2 3,264 2/18/2015
3.23.1 6,401 2/4/2015
3.23.0 6,132 1/27/2015
3.22.0 6,837 12/21/2014
3.21.1 8,368 11/13/2014
3.21.0 4,827 10/20/2014
3.20.4 3,335 10/15/2014
3.20.2 4,954 9/16/2014
3.20.1 3,668 9/7/2014
3.20.0 9,390 8/20/2014
3.19.2 5,344 8/5/2014
3.19.1 7,527 6/19/2014
3.19.0 3,596 6/12/2014
3.18.10 3,931 6/5/2014
3.18.9 3,774 6/1/2014
3.18.8 17,049 5/24/2014
3.18.7 23,927 5/17/2014
3.18.6 3,539 5/6/2014
3.18.5 5,942 4/25/2014
3.18.4 3,217 4/24/2014
3.18.3 4,220 4/13/2014
3.18.2 3,234 4/12/2014
3.18.1 19,549 3/29/2014
3.18.0 3,842 3/23/2014
3.17.0 3,584 3/15/2014
3.16.10 3,409 3/10/2014
3.16.9 3,030 3/9/2014
3.16.8 2,908 3/9/2014
3.16.7 2,884 3/8/2014
3.16.6 3,937 3/2/2014
3.16.5 4,627 1/31/2014
3.16.4 3,935 1/2/2014
3.16.3 5,348 12/22/2013
3.16.2 2,943 12/21/2013
3.16.1 3,816 12/5/2013
3.16.0 3,495 11/30/2013
3.15.1 4,238 11/26/2013
3.15.0 3,022 11/24/2013
3.14.0 2,938 11/23/2013
3.13.0 5,277 11/6/2013
3.12.1 4,039 10/20/2013
3.12.0 3,100 10/15/2013
3.11.0 3,273 10/13/2013
3.10.1 5,677 10/9/2013
3.10.0 3,229 10/8/2013
3.9.1 3,227 10/2/2013
3.9.0 3,309 9/24/2013
3.8.1 2,974 9/23/2013
3.8.0 3,122 9/22/2013
3.7.0 3,232 9/19/2013
3.6.8 3,854 9/6/2013
3.6.7 3,204 8/31/2013
3.6.6 4,618 8/1/2013
3.6.5 4,370 7/22/2013
3.6.3 3,673 7/14/2013
3.6.2 3,521 7/13/2013
3.6.1 3,455 7/11/2013
3.6.0 17,676 7/9/2013
3.5.1 3,553 7/2/2013
3.5.0 3,237 7/1/2013
3.4.1 3,429 6/27/2013
3.4.0 3,196 6/24/2013
3.3.0 3,398 6/23/2013
3.2.1 7,600 6/3/2013
3.2.0 3,654 6/1/2013
3.1.0 3,237 5/26/2013
3.0.9 3,252 5/15/2013
3.0.8 4,187 4/9/2013
3.0.7 3,252 4/6/2013
3.0.6 3,274 4/4/2013
3.0.5 3,073 4/2/2013
3.0.3 3,402 3/16/2013
3.0.2 4,169 3/5/2013
3.0.1 24,628 3/1/2013
2.16.2 5,072 1/27/2013
2.16.1 3,258 1/10/2013
2.16.0 3,182 1/6/2013
2.15.6 3,011 1/4/2013
2.15.5 3,578 12/7/2012
2.15.4 3,594 11/30/2012
2.15.3 3,243 11/29/2012
2.15.2 3,480 11/22/2012
2.15.1 3,204 11/21/2012
2.15.0 3,292 11/21/2012
2.14.1 3,333 11/19/2012
2.14.0 3,303 11/14/2012
2.13.5 3,315 11/9/2012
2.13.4 3,429 10/31/2012
2.13.3 9,584 10/9/2012
2.12.0 4,119 7/28/2012
2.11.4 3,179 7/4/2012
2.11.3 3,046 7/3/2012
2.11.2 3,059 6/24/2012
2.11.1 4,696 5/26/2012
2.11.0 3,103 5/6/2012
2.10.0 20,503 4/10/2012
2.9.2 3,249 3/7/2012
2.9.1 3,454 2/20/2012
2.9.0 3,110 2/19/2012
2.8.0 3,263 1/29/2012
2.7.2 3,213 12/28/2011
2.7.1 3,196 12/16/2011
2.7.0 3,221 12/12/2011
2.6.0 3,170 12/8/2011
2.5.2 3,105 12/8/2011
2.5.1 3,166 12/2/2011
2.5.0 3,177 12/1/2011
2.4.1 3,779 10/1/2011
2.4.0 3,216 9/18/2011
2.3.2 3,256 9/12/2011
2.3.1 3,275 9/11/2011
2.2.45 3,218 9/9/2011
2.2.44 4,661 9/6/2011
2.1.0 3,568 5/5/2011
2.0.0 3,867 4/16/2011