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

AutoFixture.NUnit4

License NuGet version NuGet preview version NuGet downloads

AutoFixture.NUnit4 is a .NET library that integrates AutoFixture with NUnit 4.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.

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

Getting Started

Basic Usage

AutoFixture.NUnit4 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.NUnit4;

[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.That(result, Is.EqualTo(a + b));
    }
}

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.NUnit4;
using AutoFixture;

[TestFixture]
public class ConsumerTests
{
    [Test, AutoData]
    public void Consumer_UsesSameDependency(
        [Frozen] Dependency dependency, Consumer consumer)
    {
        // Assert
        Assert.That(dependency, Is.SameAs(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 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 are welcome!<br/> 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 net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Framework 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

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on AutoFixture.NUnit4:

Repository Stars
recyclarr/recyclarr
Automatically sync TRaSH Guides to your Sonarr and Radarr instances
Version Downloads Last updated
5.0.0-preview0012 29,860 1/21/2025
5.0.0-preview0011 209,286 4/15/2024
4.19.0 567 4/15/2025