A streamlined, xUnit-compatible AutoFixture integration for TUnit - the modern .NET testing framework.
- xUnit-Compatible Naming - Use
[AutoData]and[InlineAutoData]just like in xUnit.AutoFixture - Seamless Migration - Drop-in replacement for teams migrating from xUnit to TUnit
- Frozen Parameters - Full support for
[Frozen]attribute with 5 matching strategies - NSubstitute Integration - Auto-mocking with
[AutoNSubstituteData] - Immutable Collections - Automatic support for ImmutableArray, ImmutableList, ImmutableDictionary, and more (.NET 5.0+)
- AutoRegister - Automatic discovery and registration of customizations marked with
[AutoRegister] - FixtureFactory - Centralized factory for creating configured IFixture instances
- Custom Generators - Built-in generators for CancellationToken and DateOnly (.NET 6+)
- Comprehensive Tests - 81 passing tests demonstrating all features
| Package | Description | NuGet |
|---|---|---|
| TestSuite.TUnit.AutoFixture | Complete library with auto-generating test data and NSubstitute auto-mocking |
All features in one package - No need to install separate packages for NSubstitute support!
Version 1.0.0 - Initial Stable Release (2026-01-21)
- ✅ [AutoData] attribute for automatic test data generation
- ✅ [InlineAutoData] for combining explicit and auto-generated parameters
- ✅ [Frozen] attribute with 5 matching strategies (ExactType, ImplementedInterfaces, DirectBaseType, BaseType, MemberOfFamily)
- ✅ NSubstitute integration with [AutoNSubstituteData] and [InlineAutoNSubstituteData]
- ✅ xUnit-compatible naming - seamless migration from xUnit.AutoFixture
- ✅ Zero warnings - strict StyleCop and SonarAnalyzer compliance
- ✅ 48 passing tests - comprehensive test coverage with FluentAssertions
- ✅ Multi-platform CI/CD - automated testing on Ubuntu, Windows, and macOS
- ✅ .NET 10.0 support
# Single package with all features included
dotnet add package TestSuite.TUnit.AutoFixture --version 1.0.1📦 View on NuGet 📝 Full Release Notes 🏷️ GitHub Release
Version 1.0.0 - Initial Stable Release (2026-01-21)
- ✅ [AutoData] attribute for automatic test data generation
- ✅ [InlineAutoData] for combining explicit and auto-generated parameters
- ✅ [Frozen] attribute with 5 matching strategies (ExactType, ImplementedInterfaces, DirectBaseType, BaseType, MemberOfFamily)
- ✅ NSubstitute integration with [AutoNSubstituteData] and [InlineAutoNSubstituteData]
- ✅ xUnit-compatible naming - seamless migration from xUnit.AutoFixture
- ✅ Zero warnings - strict StyleCop and SonarAnalyzer compliance
- ✅ 48 passing tests - comprehensive test coverage with FluentAssertions
- ✅ Multi-platform CI/CD - automated testing on Ubuntu, Windows, and macOS
- ✅ .NET 10.0 support
# Single package with all features (AutoFixture + NSubstitute)
dotnet add package TestSuite.TUnit.AutoFixtureusing TestSuite.TUnit.AutoFixture;
using TUnit.Core;
public class MyTests
{
[Test]
[AutoData]
public void Test_WithAutoGeneratedData(string text, int number, Person person)
{
// All parameters are automatically generated by AutoFixture
text.Should().NotBeNull();
number.Should().NotBe(0);
person.Should().NotBeNull();
}
[Test]
[InlineAutoData("explicit value", 42)]
public void Test_CombiningExplicitAndAutoData(
string explicitText,
int explicitNumber,
Person autoPerson)
{
// First two parameters use explicit values
// Third parameter is auto-generated
explicitText.Should().Be("explicit value");
explicitNumber.Should().Be(42);
autoPerson.Should().NotBeNull();
}
[Test]
[AutoData]
public void Test_FrozenParameters(
[Frozen] IService service,
Consumer consumer)
{
// The same IService instance is injected into Consumer
consumer.Service.Should().BeSameAs(service);
}
}using TestSuite.TUnit.AutoFixture;
using TUnit.Core;
using NSubstitute;
public class MyMockTests
{
[Test]
[AutoNSubstituteData]
public void Test_WithAutoMocking(
[Frozen] IRepository repository,
Service sut)
{
// IRepository is automatically mocked
repository.GetData().Returns("test data");
var result = sut.ProcessData();
result.Should().Be("test data");
repository.Received(1).GetData();
}
}You can use the FixtureFactory to create configured IFixture instances directly in your code:
using AutoFixture;
using TestSuite.TUnit.AutoFixture;
public class MyTests
{
[Test]
public void Test_DirectFixtureUsage()
{
// Create a configured fixture instance
var fixture = FixtureFactory.Create();
// Generate test data
var person = fixture.Create<Person>();
var numbers = fixture.CreateMany<int>(5);
// All AutoRegister customizations are automatically applied
person.Should().NotBeNull();
numbers.Should().HaveCount(5);
}
}For NSubstitute-enabled fixtures:
using AutoFixture;
using TestSuite.TUnit.AutoFixture;
public class MyTests
{
[Test]
public void Test_DirectNSubstituteFixtureUsage()
{
// Create a fixture with NSubstitute auto-mocking
var fixture = FixtureFactory.CreateWithNSubstitute();
// Generate mocked interfaces and configured objects
var service = fixture.Create<IService>();
var consumer = fixture.Freeze<Consumer>();
service.GetData().Returns("test");
consumer.GetServiceData().Should().Be("test");
}
}The FixtureFactory provides:
- ✅ Centralized Configuration - All customizations in one place
- ✅ AutoRegister Support - Automatically applies [AutoRegister] marked customizations
- ✅ Immutable Collections - Built-in support for ImmutableArray, ImmutableList, etc. (.NET 5.0+)
- ✅ Consistent Behavior - Same configuration across all test attributes
- TestSuite.TUnit.AutoFixture Documentation - Complete library usage guide
- AutoRegister Feature - Automatic customization discovery
- FixtureFactory Feature - Centralized fixture configuration
- Generators Feature - Built-in generators for CancellationToken and DateOnly
- Immutable Collections Feature - Immutable collection support (.NET 5.0+)
- Release Notes - Version history and changes
If you're migrating from xUnit, you can use the exact same attribute names:
| xUnit.AutoFixture | TestSuite.TUnit.AutoFixture | Status |
|---|---|---|
[AutoData] |
[AutoData] |
✅ Identical |
[InlineAutoData] |
[InlineAutoData] |
✅ Identical |
[Frozen] |
[Frozen] |
✅ Identical |
Matching enum |
Matching enum |
✅ Identical |
No need to learn new attribute names or refactor your tests!
| Aspect | Official AutoFixture.TUnit | TestSuite.TUnit.AutoFixture |
|---|---|---|
| Core Classes | 20+ internal classes | 6-8 core classes |
| Primary Attribute | AutoDataSourceAttribute |
AutoDataAttribute |
| Inline Attribute | AutoArgumentsAttribute |
InlineAutoDataAttribute |
| Learning Curve | Steeper | Gentler |
| Extensibility | Multiple extension points | Focused, essential points |
All core AutoFixture features are supported:
- ✅ Auto-generation of primitives, complex types, collections, enums
- ✅ Frozen parameters with 5 matching strategies (ExactType, ImplementedInterfaces, DirectBaseType, BaseType, MemberOfFamily)
- ✅ Inline data combining explicit and auto-generated values
- ✅ NSubstitute auto-mocking integration
- ✅ Customization attributes
- ✅ Complex dependency graphs
// Before (xUnit)
using AutoFixture.Xunit2;
using Xunit;
public class MyTests
{
[Theory]
[AutoData]
public void Test(string param) { }
}// After (TUnit)
using TestSuite.TUnit.AutoFixture;
using TUnit.Core;
public class MyTests
{
[Test] // Changed from [Theory]
[AutoData]
public void Test(string param) { }
}The only change needed is:
- Replace
[Theory]with[Test] - Update using statements
All [AutoData], [InlineAutoData], and [Frozen] attributes work identically!
// Before (Official AutoFixture.TUnit)
using AutoFixture.TUnit;
[Test]
[AutoDataSource] // Different name
public void Test(string param) { }// After (TestSuite.TUnit.AutoFixture)
using TestSuite.TUnit.AutoFixture;
[Test]
[AutoData] // xUnit-compatible name
public void Test(string param) { }See the test project for comprehensive examples:
- BasicAutoDataTests.cs - Primitives, complex types, collections
- FrozenDependencyTests.cs - All 5 matching strategies
- InlineAutoDataTests.cs - Hybrid explicit/auto data
- AutoNSubstituteTests.cs - Auto-mocking scenarios
- ImmutableCollectionTests.cs - Immutable collection support (.NET 5.0+)
- AutoRegisterTests.cs - Custom customization auto-registration
- FixtureFactoryTests.cs - Direct FixtureFactory usage
- NSubstituteFixtureFactoryTests.cs - NSubstitute FixtureFactory usage
- .NET 10.0 or later
- TUnit 1.10.0 or later
- AutoFixture 4.18.1 or later
Contributions are welcome! Please feel free to submit a Pull Request.
git clone https://github.com/kimlundjohansen/TUnit.AutoFixture.git
cd TUnit.AutoFixture
dotnet restore
dotnet build
dotnet testAll tests must pass with zero warnings before submitting a PR.
This project is licensed under the MIT License - see the LICENSE file for details.
- AutoFixture - The excellent fixture library
- TUnit - Modern .NET testing framework
- Official AutoFixture.TUnit - Inspiration and reference implementation
- Official AutoFixture.TUnit - Official AutoFixture organization implementation
- AutoFixture.Xunit2 - xUnit integration
- AutoFixture.NUnit3 - NUnit integration
Note: This is an independent implementation focused on xUnit compatibility and simplicity. For the official AutoFixture organization implementation, see AutoFixture.TUnit.