Workleap.Extensions.Xunit
2.0.0
Prefix Reserved
dotnet add package Workleap.Extensions.Xunit --version 2.0.0
NuGet\Install-Package Workleap.Extensions.Xunit -Version 2.0.0
<PackageReference Include="Workleap.Extensions.Xunit" Version="2.0.0" />
<PackageVersion Include="Workleap.Extensions.Xunit" Version="2.0.0" />
<PackageReference Include="Workleap.Extensions.Xunit" />
paket add Workleap.Extensions.Xunit --version 2.0.0
#r "nuget: Workleap.Extensions.Xunit, 2.0.0"
#:package Workleap.Extensions.Xunit@2.0.0
#addin nuget:?package=Workleap.Extensions.Xunit&version=2.0.0
#tool nuget:?package=Workleap.Extensions.Xunit&version=2.0.0
Workleap.Extensions.Xunit
An opinionated library that provides base unit test and fixture classes based on the Microsoft.Extensions.* packages used by modern .NET applications.
Supported frameworks
net472 and net10.0.
Getting started
There are base classes for unit and integration tests. Each test method has its own service collection configured through a class fixture.
Unit tests
Create a test class that extends BaseUnitTest<> and accepts a class fixture that extends BaseUnitFixture.
In the fixture class, you can:
- Override
ConfigureServices(services)to add, remove or update dependencies for each test method. - Override
ConfigureConfiguration(builder)to make changes to the generated sharedIConfiguration. - Access the generated
IConfigurationthroughthis.Configuration.
In the test class, you can:
- Access the fixture through
this.Fixture. - Access the .NET logger through
this.Logger- it is connected to the Xunit'sITestOutputHelper. - Access the
IServiceProviderwhich has been configured by the fixture throughthis.Services.
By default, unit tests come with an xunit-connected ILogger and an empty IConfiguration.
Integration tests
Create a test class that extends BaseIntegrationTest<> and accepts a class fixture that extends BaseIntegrationFixture.
They both inherit from their respective BaseUnit* class.
BaseIntegrationFixtureadds a defaultIHostEnvironmentwhere its environment name is:Localby default,Teston CI environments,- overridable by defining a
DOTNET_ENVIRONMENTenvironment variable, such as in .NET modern applications.
BaseIntegrationFixtureaddsappsettings.jsonandappsettings.{environment}.jsonoptional configuration providers and also an environment variable configuration provider.
Example
public class MyUnitTests : BaseUnitTest<MyUnitFixture>
{
public MyUnitTests(MyUnitFixture fixture, ITestOutputHelper testOutputHelper)
: base(fixture, testOutputHelper)
{
}
[Fact]
public void Some_Test_Works()
{
var myClass = this.Services.GetRequiredService<MyClass>();
myClass.DoWork();
}
}
public class MyUnitFixture : BaseUnitFixture
{
protected override IConfigurationBuilder ConfigureConfiguration(IConfigurationBuilder builder)
{
// Executed once per fixture instance
return base.ConfigureConfiguration(builder).AddInMemoryCollection(new Dictionary<string, string?>
{
["My:Config:Variable"] = "foo",
});
// In an integration fixture, you could add concrete configuration providers, such as:
// builder.AddAzureKeyVault(...);
}
public override IServiceCollection ConfigureServices(IServiceCollection services)
{
// Executed for each test method
return base.ConfigureServices(services)
.AddTransient<MyClass>()
.AddSingleton<IDependency>(new MyFakeDependency());
}
}
Contribute
Please see CONTRIBUTING
License
Copyright © Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/workleap/gsoft-license/blob/master/LICENSE.
| 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. |
| .NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.2
- Microsoft.Extensions.Configuration (>= 10.0.15)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.15)
- Microsoft.Extensions.Configuration.Json (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Logging (>= 10.0.15)
- Microsoft.Extensions.Logging.Configuration (>= 10.0.15)
- xunit.v3.extensibility.core (>= 4.0.3)
-
net10.0
- Microsoft.Extensions.Configuration (>= 10.0.15)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.15)
- Microsoft.Extensions.Configuration.Json (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Logging (>= 10.0.15)
- Microsoft.Extensions.Logging.Configuration (>= 10.0.15)
- xunit.v3.extensibility.core (>= 4.0.3)
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 |
|---|---|---|
| 2.0.0 | 8 | 11/25/2026 |
| 2.0.0-preview.153 | 10 | 11/25/2026 |
| 2.0.0-preview.152 | 52 | 11/23/2026 |
| 2.0.0-preview.151 | 512 | 11/13/2026 |
| 1.1.32-preview.24 | 116 | 3/30/2026 |
| 1.1.32-preview.23 | 94 | 3/14/2026 |
| 1.1.32-preview.22 | 99 | 3/12/2026 |
| 1.1.32-preview.21 | 101 | 3/11/2026 |
| 1.1.32-preview.20 | 100 | 3/9/2026 |
| 1.1.32-preview.19 | 109 | 3/4/2026 |
| 1.1.32-preview.18 | 93 | 3/1/2026 |
| 1.1.32-preview.17 | 102 | 2/23/2026 |
| 1.1.32-preview.16 | 102 | 2/19/2026 |
| 1.1.32-preview.15 | 101 | 2/16/2026 |
| 1.1.32-preview.14 | 106 | 2/12/2026 |
| 1.1.32-preview.13 | 110 | 2/9/2026 |
| 1.1.32-preview.12 | 114 | 2/2/2026 |
| 1.1.32-preview.11 | 112 | 1/26/2026 |
| 1.1.32-preview.10 | 114 | 1/18/2026 |
| 1.1.32-preview.9 | 114 | 1/16/2026 |