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" />
<PackageReference Include="XUnitTestBase" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=XUnitTestBase&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
XUnitTestBase
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 | Versions 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.
-
net8.0
- Microsoft.AspNetCore.Hosting.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Testing (>= 8.0.18)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.7)
- Microsoft.Extensions.Http (>= 9.0.7)
- Moq (>= 4.20.72)
- Moq.AutoMock (>= 3.5.0)
- xunit.abstractions (>= 2.0.3)
- xunit.extensibility.core (>= 2.9.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.