FEFF.TestFixtures.Engine 1.3.2

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

FEFF.TestFixtures

Integrations: NuGet Version NuGet Version
Fixture libraries: NuGet Version NuGet Version

✅ Replace setup/teardown methods and cumbersome "Disposable pattern" with reusable Fixtures.
✅ Fixtures can depend on other fixtures.
✅ Fixtures can be configured via standard IServiceProvider.

Fixture list

Terminology and Goals

A fixture is a reusable component used for testing purposes. Fixtures can be packaged into libraries and reused by any number of testing projects. The fixture is a class containing three optional parts:

  • setup code in constructor;
  • state;
  • teardown code in Dispose() or DisposeAsync().

A scope of fixtures defines the lifetime of those fixtures. Within a scope, each fixture is created only once (lazily on demand) and destroyed at the end of the scope. If the fixture has Dispose() or DisposeAsync(), it is called.

The available scopes are defined by the test framework used. For Xunit Integration, they are:

Scope name Description
test-case Fixtures are created and destroyed for each test case
class Fixtures are created and destroyed once for each test class
collection Fixtures are created and destroyed once for each test collection
assembly Fixtures are created and destroyed once for a test assembly

Every request for the same fixture within the same scope returns the same fixture instance. Therefore, class-, collection-, and assembly-level fixtures can share state between all tests within the same scope.

Getting started (Xunit.V3)

Add a library reference to a test project:

dotnet add package FEFF.TestFixtures.XunitV3

Add an assembly-level attribute to initialize the extension:

[assembly: FEFF.TestFixtures.Xunit.TestFixturesExtension]

Use TestContext.Current.GetFeffFixture<T>() extension method to get the required fixture instance at any moment of a test:

public class SystemUnderTest
{
    public static void Write(string filePath) =>
        File.WriteAllText(filePath, "some-data", Encoding.UTF8);
}

public class ExampleTests
{
    protected TmpDirectoryFixture TmpDir { get; } = TestContext.Current.GetFeffFixture<TmpDirectoryFixture>();

    [Fact]
    public void File__should_be_created()
    {
        // Arrange
        var filePath = TmpDir.Path + "/file.tmp";
        File.Exists(filePath).Should().BeFalse();

        // Act
        SystemUnderTest.Write(filePath);

        // Assert
        File.Exists(filePath)
            .Should().BeTrue();

        File.ReadAllText(filePath, Encoding.UTF8)
            .Should().Be("some-data");
    }
}

In this example, a TmpDir is created once the fixture is requested in the test class constructor. The scope of the fixture in this example is 'test-case'. The TmpDir and its contents are automatically deleted after the test finishes.
This example uses AwesomeAssertions for Should().
Have a look at source code for this example.

Defining other scopes for a fixture

The scope of a fixture is defined by the test creator using an overloaded method:

TestContext.Current.GetFeffFixture<T>(FixtureScopeType scopeType)

Also note that multiple instances of the fixture can exist in different scopes if needed.

Creating a fixture

Just create a class with the FixtureAttribute.
Let's examine the source code for the TmpDirectoryFixture we used above.

[Fixture]
public sealed class TmpDirectoryFixture : IDisposable
{
    public string Path { get; } = Directory.CreateTempSubdirectory().FullName;

    public void Dispose()
    {
        // double dispose guard
        try
        {
            Directory.Delete(Path, true);
        }
        catch (DirectoryNotFoundException)
        {
        }
    }
}

Where:

Fixture function Implementation
Setup Constructor
State 'Path' property
Teardown IDisposable

Fixture dependencies

Fixtures can depend on other fixtures. Dependencies are injected via the constructor:

[Fixture]
public class MyCustomFixture1
{
}

[Fixture]
public class MyCustomFixture2
{
}

[Fixture]
public record MyFixtureSet(
    MyCustomFixture1 F1,
    MyCustomFixture2 F2,
);

public class ExampleTests
{
    protected MyFixtureSet Set { get; } = TestContext.Current.GetFeffFixture<MyFixtureSet>();

    //...
}

Note:

  • All fixture dependencies (MyCustomFixture1 and MyCustomFixture2) exist in the same scope as the dependent fixture (MyFixtureSet in the example above).
  • Fixtures can't have cyclic dependencies.

Advanced usage

Add/Get Fixture by interface

Documentation is under development, see examples.

Fixture factory internals

Documentation is under development, see examples.

Advanced Fixture registration

Documentation is under development, see examples.

Configuring Fixtures

Documentation is under development, see examples.

Fixture List

Core Library

  • EnvironmentFixture
    • Snapshots the process environment and restores it after a test (the test scope)
  • TmpDirectoryFixture
    • Creates a unique directory and removes it along with its contents after a test (the test scope)
    • Can optionally skip deletion
  • TmpScopeIdFixture
    • Generates a string which is unique for each scope (e.g. for each test)

AspNetCore Fixture Library

  • TestApplicationFixture
    • Starts and stops the application via TestHost
    • Modifies Configuration/ServiceCollection before the application starts
  • AppClientFixture
    • Creates/Disposes an HttpClient for testing
  • AppServicesFixture
    • Accesses the application's service provider in the test context
  • FakeLoggerFixture (extension to TestApplicationFixture)
    • Replaces Logger<> with FakeLogger
  • FakeTimeFixture (extension to TestApplicationFixture)
    • Replaces TimeProvider with FakeTimeProvider
  • FakeRandomFixture (extension to TestApplicationFixture)
    • Replaces Random with FakeRandom

AspNetCore Fixture Library [work in progress]

  • Generates a unique database name for test isolation
  • Generates a unique Redis key prefix for test isolation
  • Generates a unique S3 path prefix for test isolation
  • Creates a SignalRClient for testing
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  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 (3)

Showing the top 3 NuGet packages that depend on FEFF.TestFixtures.Engine:

Package Downloads
FEFF.TestFixtures.XunitV3

Xunit extension, adds 'FEFF.TestFixtures': Replace setup/teardown methods with reusable Fixtures, dependency injection for fixtures.

FEFF.TestFixtures.TUnit

TUnit extension, adds 'FEFF.TestFixtures'.

FEFF.TestFixtures.XunitV4

xUnit v4 extension, adds 'FEFF.TestFixtures'.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.6.1 152 6/1/2026
1.6.0 309 5/6/2026
1.5.1 132 4/29/2026
1.5.0 254 4/28/2026
1.4.6 169 4/23/2026
1.4.5 166 4/22/2026
1.4.4 133 4/15/2026
1.4.3-alpha 128 4/15/2026
1.4.2 222 4/13/2026
1.4.1 142 4/11/2026
1.3.5 132 4/11/2026
1.3.4 138 4/9/2026
1.3.3 214 4/9/2026
1.3.2 155 4/5/2026
1.3.1 138 4/3/2026
1.3.0 139 4/2/2026
0.0.12-alpha 131 4/15/2026