AutoFixture.Xunit
4.19.0
Prefix Reserved
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
<PackageReference Include="AutoFixture.Xunit" Version="4.19.0" />
<PackageVersion Include="AutoFixture.Xunit" Version="4.19.0" />
<PackageReference Include="AutoFixture.Xunit" />
paket add AutoFixture.Xunit --version 4.19.0
#r "nuget: AutoFixture.Xunit, 4.19.0"
#addin nuget:?package=AutoFixture.Xunit&version=4.19.0
#tool nuget:?package=AutoFixture.Xunit&version=4.19.0
AutoFixture.xUnit
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.
[!WARNING] 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.
[!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 (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 | |||
Assertion idioms | AutoFixture.Idioms | |||
Seed extensions | AutoFixture.SeedExtensions |
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 | |||
NSubstitute | AutoFixture.AutoNSubstitute | |||
FakeItEasy | AutoFixture.AutoFakeItEasy | |||
Rhino Mocks | AutoFixture.AutoRhinoMocks |
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 | |||
xUnit v2 | AutoFixture.Xunit2 | |||
xUnit v1 | AutoFixture.Xunit | |||
NUnit v4 | AutoFixture.NUnit4 | |||
NUnit v3 | AutoFixture.NUnit3 | |||
NUnit v2 | AutoFixture.NUnit2 | |||
Foq | AutoFixture.AutoFoq |
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 | Versions 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. |
-
.NETFramework 4.5.2
- AutoFixture (>= 4.18.1)
- xunit (>= 1.8.0.1549 && < 2.0.0)
- xunit.extensions (>= 1.8.0.1549 && < 2.0.0)
-
.NETFramework 4.6.2
- AutoFixture (>= 4.18.1)
- xunit (>= 1.8.0.1549 && < 2.0.0)
- xunit.extensions (>= 1.8.0.1549 && < 2.0.0)
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 | 384 | 1/21/2025 |
5.0.0-preview0011 | 243 | 4/15/2024 |
5.0.0-preview0010 | 126 | 3/25/2024 |
5.0.0-preview0009 | 121 | 3/10/2024 |
5.0.0-preview0008 | 155 | 2/18/2024 |
5.0.0-preview0007 | 7,158 | 12/9/2023 |
5.0.0-preview0006 | 136 | 12/4/2023 |
5.0.0-pdb-test0003 | 130 | 12/10/2023 |
5.0.0-pdb-test0002 | 107 | 12/10/2023 |
5.0.0-pdb-test0001 | 109 | 12/10/2023 |
5.0.0-dataattributes0001 | 139 | 12/27/2023 |
4.19.0 | 437 | 4/14/2025 |
4.18.1 | 39,182 | 11/28/2023 |
4.18.0 | 34,355 | 2/21/2023 |
4.17.0 | 88,592 | 4/20/2021 |
4.16.0 | 3,769 | 4/1/2021 |
4.15.0 | 27,038 | 12/18/2020 |
4.14.0 | 43,999 | 9/10/2020 |
4.13.0 | 10,191 | 7/9/2020 |
4.12.0 | 1,155 | 6/28/2020 |
4.11.0 | 72,754 | 7/8/2019 |
4.10.0 | 4,239 | 6/13/2019 |
4.9.0 | 2,807 | 5/28/2019 |
4.8.0 | 4,604 | 1/30/2019 |
4.7.0 | 1,314 | 1/26/2019 |
4.6.0 | 1,652 | 12/10/2018 |
4.5.1 | 1,589 | 11/25/2018 |
4.5.0 | 11,941 | 7/12/2018 |
4.4.0 | 2,299 | 5/26/2018 |
4.3.0 | 1,795 | 5/2/2018 |
4.2.1 | 2,038 | 4/16/2018 |
4.2.0 | 5,320 | 3/21/2018 |
4.1.0 | 2,291 | 2/15/2018 |
4.0.1 | 2,051 | 1/22/2018 |
4.0.0 | 7,677 | 1/10/2018 |
4.0.0-rc1 | 1,067 | 10/18/2017 |
3.51.0 | 51,745 | 10/5/2017 |
3.50.7 | 12,363 | 9/18/2017 |
3.50.6 | 6,084 | 8/16/2017 |
3.50.5 | 23,327 | 8/9/2017 |
3.50.4 | 1,565 | 8/7/2017 |
3.50.3 | 17,444 | 7/5/2017 |
3.50.2 | 68,096 | 8/31/2016 |
3.50.1 | 6,644 | 8/12/2016 |
3.50.0 | 4,123 | 8/11/2016 |
3.49.1 | 18,151 | 8/3/2016 |
3.49.0 | 2,927 | 7/5/2016 |
3.48.0 | 2,019 | 6/28/2016 |
3.47.8 | 5,480 | 6/19/2016 |
3.47.7 | 1,841 | 6/18/2016 |
3.47.6 | 5,182 | 6/13/2016 |
3.47.5 | 1,856 | 6/11/2016 |
3.47.4 | 9,572 | 6/3/2016 |
3.47.3 | 25,164 | 6/2/2016 |
3.47.2 | 1,692 | 6/2/2016 |
3.47.1 | 1,688 | 6/1/2016 |
3.47.0 | 1,685 | 5/31/2016 |
3.46.0 | 29,796 | 5/15/2016 |
3.45.3 | 1,683 | 5/12/2016 |
3.45.2 | 2,458 | 5/7/2016 |
3.45.1 | 2,275 | 4/25/2016 |
3.45.0 | 3,424 | 4/24/2016 |
3.44.1 | 3,412 | 4/20/2016 |
3.44.0 | 2,087 | 4/15/2016 |
3.43.4 | 1,779 | 4/14/2016 |
3.43.3 | 1,672 | 4/13/2016 |
3.43.2 | 1,771 | 4/12/2016 |
3.43.1 | 1,679 | 4/10/2016 |
3.43.0 | 3,550 | 3/28/2016 |
3.42.0 | 1,963 | 3/20/2016 |
3.41.1 | 6,085 | 3/13/2016 |
3.41.0 | 1,807 | 3/12/2016 |
3.40.0 | 7,494 | 2/2/2016 |
3.39.0 | 2,162 | 1/22/2016 |
3.38.1 | 1,971 | 1/3/2016 |
3.38.0 | 1,695 | 12/31/2015 |
3.37.3 | 2,051 | 12/8/2015 |
3.37.2 | 1,617 | 12/8/2015 |
3.37.1 | 1,656 | 12/3/2015 |
3.37.0 | 1,949 | 11/25/2015 |
3.36.12 | 3,437 | 11/20/2015 |
3.36.11 | 2,203 | 11/16/2015 |
3.36.9 | 30,767 | 10/21/2015 |
3.36.8 | 2,601 | 10/8/2015 |
3.36.1 | 1,882 | 10/6/2015 |
3.36.0 | 2,872 | 10/2/2015 |
3.35.1 | 1,908 | 10/2/2015 |
3.34.2 | 2,936 | 9/16/2015 |
3.34.1 | 1,843 | 9/16/2015 |
3.34.0 | 1,956 | 9/12/2015 |
3.33.0 | 1,923 | 9/5/2015 |
3.32.2 | 1,700 | 9/5/2015 |
3.32.0 | 1,746 | 9/5/2015 |
3.31.0 | 4,335 | 7/31/2015 |
3.30.8 | 5,414 | 6/17/2015 |
3.30.7 | 1,938 | 6/14/2015 |
3.30.6 | 2,219 | 6/5/2015 |
3.30.4 | 4,228 | 4/29/2015 |
3.30.3 | 2,696 | 4/19/2015 |
3.30.2 | 3,050 | 4/11/2015 |
3.30.1 | 7,261 | 4/10/2015 |
3.30.0 | 36,432 | 4/9/2015 |
3.29.0 | 1,803 | 4/9/2015 |
3.27.0 | 1,796 | 4/8/2015 |
3.25.0 | 1,768 | 4/8/2015 |
3.24.6 | 1,929 | 4/7/2015 |
3.24.5 | 1,770 | 4/6/2015 |
3.24.4 | 1,734 | 4/4/2015 |
3.24.3 | 5,606 | 3/12/2015 |
3.24.2 | 5,295 | 3/7/2015 |
3.24.1 | 6,342 | 2/28/2015 |
3.24.0 | 3,566 | 2/19/2015 |
3.23.2 | 2,189 | 2/18/2015 |
3.23.1 | 5,213 | 2/4/2015 |
3.23.0 | 5,076 | 1/27/2015 |
3.22.0 | 5,626 | 12/21/2014 |
3.21.1 | 7,150 | 11/13/2014 |
3.21.0 | 3,746 | 10/20/2014 |
3.20.4 | 2,269 | 10/15/2014 |
3.20.2 | 3,881 | 9/16/2014 |
3.20.1 | 2,579 | 9/7/2014 |
3.20.0 | 6,969 | 8/20/2014 |
3.19.2 | 4,297 | 8/5/2014 |
3.19.1 | 6,447 | 6/19/2014 |
3.19.0 | 2,554 | 6/12/2014 |
3.18.10 | 2,885 | 6/5/2014 |
3.18.9 | 2,730 | 6/1/2014 |
3.18.8 | 15,817 | 5/24/2014 |
3.18.7 | 22,668 | 5/17/2014 |
3.18.6 | 2,464 | 5/6/2014 |
3.18.5 | 4,876 | 4/25/2014 |
3.18.4 | 2,148 | 4/24/2014 |
3.18.3 | 3,103 | 4/13/2014 |
3.18.2 | 2,167 | 4/12/2014 |
3.18.1 | 18,389 | 3/29/2014 |
3.18.0 | 2,799 | 3/23/2014 |
3.17.0 | 2,512 | 3/15/2014 |
3.16.10 | 2,366 | 3/10/2014 |
3.16.9 | 1,983 | 3/9/2014 |
3.16.8 | 1,840 | 3/9/2014 |
3.16.7 | 1,817 | 3/8/2014 |
3.16.6 | 2,891 | 3/2/2014 |
3.16.5 | 3,580 | 1/31/2014 |
3.16.4 | 2,872 | 1/2/2014 |
3.16.3 | 4,273 | 12/22/2013 |
3.16.2 | 1,872 | 12/21/2013 |
3.16.1 | 2,772 | 12/5/2013 |
3.16.0 | 2,417 | 11/30/2013 |
3.15.1 | 2,575 | 11/26/2013 |
3.15.0 | 1,956 | 11/24/2013 |
3.14.0 | 1,890 | 11/23/2013 |
3.13.0 | 4,000 | 11/6/2013 |
3.12.1 | 2,824 | 10/20/2013 |
3.12.0 | 2,048 | 10/15/2013 |
3.11.0 | 2,196 | 10/13/2013 |
3.10.1 | 4,602 | 10/9/2013 |
3.10.0 | 2,154 | 10/8/2013 |
3.9.1 | 2,167 | 10/2/2013 |
3.9.0 | 2,254 | 9/24/2013 |
3.8.1 | 1,898 | 9/23/2013 |
3.8.0 | 2,047 | 9/22/2013 |
3.7.0 | 2,173 | 9/19/2013 |
3.6.8 | 2,769 | 9/6/2013 |
3.6.7 | 2,159 | 8/31/2013 |
3.6.6 | 3,557 | 8/1/2013 |
3.6.5 | 3,307 | 7/22/2013 |
3.6.3 | 2,621 | 7/14/2013 |
3.6.2 | 2,463 | 7/13/2013 |
3.6.1 | 2,396 | 7/11/2013 |
3.6.0 | 16,618 | 7/9/2013 |
3.5.1 | 2,488 | 7/2/2013 |
3.5.0 | 2,179 | 7/1/2013 |
3.4.1 | 2,338 | 6/27/2013 |
3.4.0 | 2,141 | 6/24/2013 |
3.3.0 | 2,317 | 6/23/2013 |
3.2.1 | 6,544 | 6/3/2013 |
3.2.0 | 2,570 | 6/1/2013 |
3.1.0 | 2,148 | 5/26/2013 |
3.0.9 | 2,200 | 5/15/2013 |
3.0.8 | 3,104 | 4/9/2013 |
3.0.7 | 2,179 | 4/6/2013 |
3.0.6 | 2,213 | 4/4/2013 |
3.0.5 | 1,988 | 4/2/2013 |
3.0.3 | 2,317 | 3/16/2013 |
3.0.2 | 3,086 | 3/5/2013 |
3.0.1 | 22,972 | 3/1/2013 |
2.16.2 | 3,982 | 1/27/2013 |
2.16.1 | 2,198 | 1/10/2013 |
2.16.0 | 2,097 | 1/6/2013 |
2.15.6 | 1,952 | 1/4/2013 |
2.15.5 | 2,498 | 12/7/2012 |
2.15.4 | 2,513 | 11/30/2012 |
2.15.3 | 2,183 | 11/29/2012 |
2.15.2 | 2,396 | 11/22/2012 |
2.15.1 | 2,146 | 11/21/2012 |
2.15.0 | 2,228 | 11/21/2012 |
2.14.1 | 2,273 | 11/19/2012 |
2.14.0 | 2,216 | 11/14/2012 |
2.13.5 | 2,225 | 11/9/2012 |
2.13.4 | 2,368 | 10/31/2012 |
2.13.3 | 8,496 | 10/9/2012 |
2.12.0 | 3,009 | 7/28/2012 |
2.11.4 | 2,138 | 7/4/2012 |
2.11.3 | 1,980 | 7/3/2012 |
2.11.2 | 2,010 | 6/24/2012 |
2.11.1 | 3,618 | 5/26/2012 |
2.11.0 | 2,028 | 5/6/2012 |
2.10.0 | 17,735 | 4/10/2012 |
2.9.2 | 2,203 | 3/7/2012 |
2.9.1 | 2,371 | 2/20/2012 |
2.9.0 | 2,033 | 2/19/2012 |
2.8.0 | 2,214 | 1/29/2012 |
2.7.2 | 2,159 | 12/28/2011 |
2.7.1 | 2,146 | 12/16/2011 |
2.7.0 | 2,167 | 12/12/2011 |
2.6.0 | 2,094 | 12/8/2011 |
2.5.2 | 2,038 | 12/8/2011 |
2.5.1 | 2,111 | 12/2/2011 |
2.5.0 | 2,134 | 12/1/2011 |
2.4.1 | 2,692 | 10/1/2011 |
2.4.0 | 2,166 | 9/18/2011 |
2.3.2 | 2,158 | 9/12/2011 |
2.3.1 | 2,198 | 9/11/2011 |
2.2.45 | 2,164 | 9/9/2011 |
2.2.44 | 3,572 | 9/6/2011 |
2.1.0 | 2,505 | 5/5/2011 |
2.0.0 | 2,652 | 4/16/2011 |