Hallett.AutoFixture.NUnit4 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Hallett.AutoFixture.NUnit4 --version 1.0.2
                    
NuGet\Install-Package Hallett.AutoFixture.NUnit4 -Version 1.0.2
                    
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="Hallett.AutoFixture.NUnit4" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hallett.AutoFixture.NUnit4" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Hallett.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 Hallett.AutoFixture.NUnit4 --version 1.0.2
                    
#r "nuget: Hallett.AutoFixture.NUnit4, 1.0.2"
                    
#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 Hallett.AutoFixture.NUnit4@1.0.2
                    
#: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=Hallett.AutoFixture.NUnit4&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Hallett.AutoFixture.NUnit4&version=1.0.2
                    
Install as a Cake Tool

Hallett.AutoFixture.NUnit4

Custom frozen attributes

The NUnit FrozenAttribute is reliant upon test method parameter names when Matching.PropertyName, Matching.FieldName, Matching.ParameterName.

The FrozenNamedAttribute allows for nameof.

The FrozenParameterIndexAttribute cannot use nameof so instead you specify a Type that has a method that will be found by an IMethodQuery ( default ModestConstructorQuery) containing a parameter that is a base type of the attributed test method parameter type.

If there is more than one parameter then you can specify which one with the index constructor parameter. If you want the second then the index is 1, the parameter position is irrelevant.

To change from ModestConstructorQuery set the MethodQueryType property

NUnit parameterized tests with CancelAfterAttribute

Of the NUnit parameterized tests only TestCaseAttribute has an AutoFixture version, InlineAutoDataAttribute.

AutoFixture.xUnit3 on the other hand has MemberAutoDataAttribute and ClassAutoDataAttribute that together work similar to TestCaseSourceAttribute.

These two are on the Version 5 roadmap for NUnit

The existing AutoFixture attributes for NUnit, AutoDataAttribute and InlineAutoDataAttribute, do not support the CancelAfterAttribute.

These can be replaced with AutoTestAttribute and AutoTestCaseAttribute which support the CancelAfterAttribute.

There is also a generic version of these, so that the IFixture does not have to come from Func<IFixture>.

e.g

    public class AutoTestAttribute<TFixtureFactory>()
        : AutoTestAttribute(new TFixtureFactory().Create) where TFixtureFactory : IFixtureFactory, new()
    {
    }

The remaining parameterized tests are supported with :

A new AutoFixture, CancelAfterAttribute aware, version of TestCaseSourceAttribute - AutoTestCaseSourceAttribute

For the following NUnit attributes ( IParameterDataSource )

The RandomAttribute

The RangeAttribute

The ValuesAttribute

The ValueSourceAttribute

Their functionality comes from the abstract CombiningStrategyAttribute with derivations supplying

protected CombiningStrategyAttribute(ICombiningStrategy strategy, IParameterDataProvider provider)

The derivations CombinatorialAttribute, PairwiseAttribute, SequentialAttribute all provide ParameterDataSourceProvider that work with the IParameterDataSource attributes above.

Each provide a corresponding stategy - CombinatorialStrategy, PairwiseStrategy and SequentialStrategy.

The final NUnit parameterization is the TheoryAttribute, whose DatapointProvider looks for [DatapointAttribute] and [DatapointSourceAttribute] on fields, properties and non void methods.

public TheoryAttribute(bool searchInDeclaringTypes = false) : base(
    new CombinatorialStrategy(),
    new ParameterDataProvider(new DatapointProvider(searchInDeclaringTypes), new ParameterDataSourceProvider()))
{
}

There are "Auto" versions of CombiningStrategyAttribute and derivations.

Note that with NUnit and IParameterDataSource attributes it is not necessary to apply the CombinatorialAttribute to the test method as it is the default. This is not true with AutoCombinatorialAttribute.

For AutoCombiningStrategyAttribute to work you need to apply [Auto] on the first parameter to be supplied by AutoFixture.

AutoTestCaseSourceAttribute

The sources have to be IEnumerable containing IEnumerable items.

It has similar constructors to TestCaseSourceAttribute with the addition of constructor parameters for when the test case source comes from the supplied Type that inherits IEnumerable containing IEnumerable items.

AutoTestCaseSourceAttribute / AutoCombiningStrategyAttribute common

Generic and non generic versions

For AutoTestCaseSourceAttribute and "Auto" versions of CombiningStrategyAttribute and derivations there is also a generic attribute version.

The generic attribute argument is TFixtureFactory where TFixtureFactory : IFixtureFactory, new().

For the non generic attribute, if you need an IFixture different to the default new Fixture() there are two solutions :

  1. Derive and supply your own Func<IFixture> to the base type.

  2. If you already have an InlineAutoDataAttribute ( or AutoTestCaseAttribute ) derivation then you can set the

InlineAutoDataAttributeType property. The type has to have a single constructor params object?[] values and will instantiated with reflection.

Behaviour

These get values from their respective sources then supply the remaining from AutoFixture.

If the final parameter is a CancellationToken and the test method has a CancelAfterAttribute then the CancellationToken is supplied by NUnit.

If you want AutoFixture to supply the CancellationToken then apply [Auto] to that parameter.

This also applies to AutoTestAttribute and AutoTestCaseAttribute.

Similar to the xUnit MemberAutoDataAttribute and ClassAutoDataAttribute it is possible to [Freeze] values from the source. Just apply [Frozen] or an attribute with interface IFreezeTestCaseArgument like FrozenNamedAttribute or FrozenParameterIndexAttribute to the parameter.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows 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

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 91 6/29/2026
1.0.3 96 6/29/2026
1.0.2 91 6/29/2026
1.0.1 101 6/29/2026
1.0.0 98 6/28/2026