AutoFixture.NUnit2 5.0.0

Prefix Reserved
dotnet add package AutoFixture.NUnit2 --version 5.0.0
                    
NuGet\Install-Package AutoFixture.NUnit2 -Version 5.0.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.NUnit2" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoFixture.NUnit2" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AutoFixture.NUnit2" />
                    
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.NUnit2 --version 5.0.0
                    
#r "nuget: AutoFixture.NUnit2, 5.0.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.
#addin nuget:?package=AutoFixture.NUnit2&version=5.0.0
                    
Install AutoFixture.NUnit2 as a Cake Addin
#tool nuget:?package=AutoFixture.NUnit2&version=5.0.0
                    
Install AutoFixture.NUnit2 as a Cake Tool

AutoFixture.NUnit2

License NuGet version NuGet preview version NuGet downloads

AutoFixture.NUnit2 is a .NET library that integrates AutoFixture with NUnit 2.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 NUnit 2 package is deprecated.<br/> This package is intended for legacy projects that are still using NUnit 2.x.<br/> Use at your own risk.

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.NUnit2 --version x.x.x
<PackageReference Include="AutoFixture.NUnit2" Version="x.x.x" />

Getting Started

Basic Usage

AutoFixture.NUnit2 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 NUnit.Framework;
using AutoFixture.NUnit2;

[TestFixture]
public class CalculatorTests
{
    [Test, 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);
    }
}

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 NUnit.Framework;
using AutoFixture.NUnit2;
using AutoFixture;

[TestFixture]
public class ConsumerTests
{
    [Test, 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.NUnit2 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 (1)

Showing the top 1 NuGet packages that depend on AutoFixture.NUnit2:

Package Downloads
AutoFixture.AutoMoq.AutoSetup

Extending AutoFixture.AutoMoq to automatically Setup all calls on a mocked interface or abstract class.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.0 275 a month ago
5.0.0-preview0012 80 4 months ago
5.0.0-preview0011 131 4/15/2024
5.0.0-preview0010 103 3/25/2024
5.0.0-preview0009 112 3/10/2024
4.18.1 6,909 11/28/2023
4.18.0 30,404 2/21/2023
4.17.0 7,008 4/20/2021
4.16.0 620 4/1/2021
4.15.0 9,026 12/18/2020
4.14.0 699 9/10/2020
4.13.0 4,458 7/9/2020
4.12.0 629 6/28/2020
4.11.0 11,834 7/8/2019
4.10.0 932 6/13/2019
4.9.0 847 5/28/2019
4.8.0 3,232 1/30/2019
4.7.0 861 1/26/2019
4.6.0 1,059 12/10/2018
4.5.1 966 11/25/2018
4.5.0 38,729 7/12/2018
4.4.0 6,452 5/26/2018
4.3.0 1,669 5/2/2018
4.2.1 1,491 4/16/2018
4.2.0 10,516 3/21/2018
4.1.0 18,657 2/15/2018
4.0.1 1,354 1/22/2018
4.0.0 1,442 1/10/2018
4.0.0-rc1 1,048 10/18/2017
3.51.0 27,650 10/5/2017
3.50.7 1,350 9/18/2017
3.50.6 9,580 8/16/2017
3.50.5 1,345 8/9/2017
3.50.4 3,896 8/7/2017
3.50.3 5,117 7/5/2017
3.50.2 107,778 8/31/2016
3.50.1 4,112 8/12/2016
3.50.0 1,355 8/11/2016
3.49.1 2,121 8/3/2016
3.49.0 6,899 7/5/2016
3.48.0 1,519 6/28/2016
3.47.8 1,579 6/19/2016
3.47.7 1,537 6/18/2016
3.47.6 3,629 6/13/2016
3.47.5 1,684 6/11/2016
3.47.4 1,572 6/3/2016
3.47.3 1,386 6/2/2016
3.47.2 1,409 6/2/2016
3.47.1 1,440 6/1/2016
3.47.0 1,581 5/31/2016
3.46.0 15,346 5/15/2016
3.45.3 2,921 5/12/2016
3.45.2 1,573 5/7/2016
3.45.1 2,917 4/25/2016
3.45.0 2,530 4/24/2016
3.44.1 5,071 4/20/2016
3.44.0 1,463 4/15/2016
3.43.4 1,381 4/14/2016
3.43.3 1,333 4/13/2016
3.43.2 1,379 4/12/2016
3.43.1 1,545 4/10/2016
3.43.0 3,654 3/28/2016
3.42.0 1,520 3/20/2016
3.41.1 5,038 3/13/2016
3.41.0 1,523 3/12/2016
3.40.0 6,432 2/2/2016
3.39.0 14,953 1/22/2016
3.38.1 5,346 1/3/2016
3.38.0 1,385 12/31/2015
3.37.3 3,129 12/8/2015
3.37.2 1,326 12/8/2015
3.37.1 3,025 12/3/2015
3.37.0 2,422 11/25/2015
3.36.12 2,021 11/20/2015
3.36.11 2,418 11/16/2015
3.36.9 2,787 10/21/2015
3.36.8 3,330 10/8/2015
3.36.1 1,898 10/6/2015
3.36.0 3,460 10/2/2015
3.35.1 1,584 10/2/2015
3.34.2 2,191 9/16/2015
3.34.1 1,487 9/16/2015
3.34.0 2,407 9/12/2015
3.33.0 1,533 9/5/2015
3.32.2 1,439 9/5/2015
3.32.0 1,500 9/5/2015
3.31.0 4,167 7/31/2015
3.30.8 17,360 6/17/2015
3.30.7 1,526 6/14/2015
3.30.6 2,123 6/5/2015
3.30.4 4,441 4/29/2015
3.30.3 1,819 4/19/2015
3.30.2 1,652 4/11/2015
3.30.1 1,507 4/10/2015
3.30.0 1,495 4/9/2015
3.29.0 1,461 4/9/2015
3.27.0 1,451 4/8/2015
3.25.0 1,444 4/8/2015
3.24.6 1,455 4/7/2015
3.24.5 1,494 4/6/2015
3.24.4 1,477 4/4/2015
3.24.3 18,055 3/12/2015
3.24.2 1,539 3/7/2015
3.24.1 2,661 2/28/2015
3.24.0 2,194 2/19/2015
3.23.2 1,862 2/18/2015
3.23.1 1,729 2/4/2015
3.23.0 1,536 1/27/2015
3.22.0 2,653 12/21/2014
3.21.1 10,649 11/13/2014
3.21.0 2,188 10/20/2014
3.20.4 1,985 10/15/2014
3.20.2 1,889 9/16/2014
3.20.1 1,698 9/7/2014
3.20.0 2,259 8/20/2014
3.19.2 139,769 8/5/2014
3.19.1 3,727 6/19/2014
3.19.0 1,630 6/12/2014
3.18.10 1,631 6/5/2014
3.18.9 1,542 6/1/2014
3.18.8 1,577 5/24/2014
3.18.7 1,645 5/17/2014
3.18.6 1,610 5/6/2014
3.18.5 1,822 4/25/2014
3.18.4 1,795 4/24/2014
3.18.3 1,806 4/13/2014
3.18.2 1,723 4/12/2014
3.18.1 1,777 3/29/2014
3.18.0 1,630 3/23/2014
3.17.0 1,729 3/15/2014
3.16.10 1,739 3/10/2014
3.16.9 1,567 3/9/2014
3.16.8 1,549 3/9/2014
3.16.7 1,572 3/8/2014
3.16.6 1,616 3/2/2014
3.16.5 2,319 1/31/2014
3.16.4 1,756 1/2/2014
3.16.3 1,619 12/22/2013
3.16.2 1,537 12/21/2013
3.16.1 1,654 12/5/2013
3.16.0 1,781 11/30/2013
3.15.1 1,614 11/26/2013
3.15.0 1,584 11/24/2013
3.14.0 1,658 11/23/2013
3.13.0 1,594 11/6/2013
3.12.1 1,700 10/20/2013
3.12.0 1,794 10/15/2013
3.11.0 1,598 10/13/2013
3.10.1 1,829 10/9/2013
3.10.0 1,622 10/8/2013
3.9.1 2,356 10/2/2013
3.9.0 1,715 9/24/2013