Hallett.AutoFixture.NUnit4
1.0.2
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
<PackageReference Include="Hallett.AutoFixture.NUnit4" Version="1.0.2" />
<PackageVersion Include="Hallett.AutoFixture.NUnit4" Version="1.0.2" />
<PackageReference Include="Hallett.AutoFixture.NUnit4" />
paket add Hallett.AutoFixture.NUnit4 --version 1.0.2
#r "nuget: Hallett.AutoFixture.NUnit4, 1.0.2"
#:package Hallett.AutoFixture.NUnit4@1.0.2
#addin nuget:?package=Hallett.AutoFixture.NUnit4&version=1.0.2
#tool nuget:?package=Hallett.AutoFixture.NUnit4&version=1.0.2
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
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 :
Derive and supply your own Func<IFixture> to the base type.
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 | Versions 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. |
-
net10.0
- AutoFixture (>= 4.18.1)
- AutoFixture.NUnit4 (>= 4.19.0)
- NUnit (>= 4.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.