XUnitTestBase 1.1.1

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

XUnitTestBase

NuGet License Build

XUnitTestBase v1.0 โ€” A clean, extensible test foundation for .NET with auto-mocking, integration testing, and developer-friendly conventions.


๐ŸŽฏ Purpose

XUnitTestBase provides a standardized and developer-friendly test foundation for .NET applications using:

  • ๐Ÿงช xUnit
  • ๐Ÿค– Moq with AutoMocker
  • ๐Ÿงฑ WebApplicationFactory<T> for integration testing

It helps teams write cleaner, faster, and more maintainable unit and integration tests with minimal setup.


โœจ Key Features

  • โœ… TestSubject<T>: auto-mocked unit test base class using Moq.AutoMocker
  • โœ… MockOf<T>(): get & verify dependency mocks
  • โœ… With<T>(): override mocks or inject custom test doubles
  • โœ… IntegrationTestBase<T>: lightweight base for API integration tests
  • โœ… Support for WebApplicationFactory, InMemory EF Core, and fake authentication

๐Ÿ” Integration Testing

Use IntegrationTestBase<T> to verify your app's full stack:

public class UserApiTests : IntegrationTestBase<Program>
{
    public UserApiTests() : base(services =>
    {
        services.AddDbContext<AppDbContext>(options =>
            options.UseInMemoryDatabase("TestDb"));
    }) { }

    [Fact]
    public async Task GetUser_ReturnsOk()
    {
        var response = await Client.GetAsync("/api/users/1");
        response.EnsureSuccessStatusCode();
    }
}

๐Ÿงช Unit Testing

Extend TestSubject<T> for clean unit tests:

public class UserServiceTests : TestSubject<UserService>
{
    [Fact]
    public async Task Register_CallsAllDependencies()
    {
        var user = FakeBuilder.Create<User>();

        MockOf<IUserRepository>()
            .Setup(r => r.GetByEmailAsync(user.Email))
            .ReturnsAsync((User?)null);

        await Subject.Register(user);

        MockOf<IEmailSender>().Verify(s => s.SendWelcomeAsync(user.Email), Times.Once);
        MockOf<IAuditLogger>().Verify(l => l.LogEvent("UserRegistered", user.Email), Times.Once);
    }
}

๐Ÿ’ก Example Highlights

  • ๐Ÿงช Auto-mocking multiple dependencies
  • ๐Ÿ” Overriding mocks with real or fake implementations
  • ๐Ÿš€ End-to-end HTTP testing with in-memory HttpClient

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 was computed.  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.1.1 127 7/14/2025
1.1.0 116 7/13/2025
1.0.0 81 7/11/2025