Workleap.Extensions.Xunit
1.0.3-preview.16
Prefix Reserved
See the version list below for details.
dotnet add package Workleap.Extensions.Xunit --version 1.0.3-preview.16
NuGet\Install-Package Workleap.Extensions.Xunit -Version 1.0.3-preview.16
<PackageReference Include="Workleap.Extensions.Xunit" Version="1.0.3-preview.16" />
<PackageVersion Include="Workleap.Extensions.Xunit" Version="1.0.3-preview.16" />
<PackageReference Include="Workleap.Extensions.Xunit" />
paket add Workleap.Extensions.Xunit --version 1.0.3-preview.16
#r "nuget: Workleap.Extensions.Xunit, 1.0.3-preview.16"
#addin nuget:?package=Workleap.Extensions.Xunit&version=1.0.3-preview.16&prerelease
#tool nuget:?package=Workleap.Extensions.Xunit&version=1.0.3-preview.16&prerelease
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.
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 makes changes to the generated sharedIConfiguration
. - Access the generated
IConfiguration
throughthis.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
IServiceProvider
which 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.
BaseIntegrationFixture
adds a defaultIHostEnvironment
where its environment name is:Local
by default,Test
on CI environments,- overrideable by defining a
DOTNET_ENVIRONMENT
environment variable, such as in .NET modern applications.
BaseIntegrationFixture
addsappsettings.json
andappsettings.{environment}.json
optional 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>()
.AddTransient<IDependency>(new MyFakeDependency());
}
}
Contribute
Please see CONTRIBUTING
License
Copyright © 2022, Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/gsoft-inc/gsoft-license/blob/master/LICENSE.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 6.0.0)
- Microsoft.Extensions.Configuration.Json (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- xunit.core (>= 2.6.6)
-
net6.0
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 6.0.0)
- Microsoft.Extensions.Configuration.Json (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- xunit.core (>= 2.6.6)
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.11 | 0 | 6/29/2025 |
1.1.11-preview.2 | 106 | 6/18/2025 |
1.1.10 | 194 | 6/15/2025 |
1.1.10-preview.2 | 102 | 6/14/2025 |
1.1.10-preview.1 | 240 | 6/10/2025 |
1.1.9 | 605 | 6/8/2025 |
1.1.9-preview.1 | 117 | 6/3/2025 |
1.1.8 | 548 | 6/1/2025 |
1.1.8-preview.1 | 117 | 5/26/2025 |
1.1.7 | 215 | 5/25/2025 |
1.1.7-preview.1 | 112 | 5/20/2025 |
1.1.6 | 406 | 5/18/2025 |
1.1.6-preview.2 | 99 | 5/17/2025 |
1.1.6-preview.1 | 206 | 5/13/2025 |
1.1.5 | 321 | 5/11/2025 |
1.1.5-preview.2 | 120 | 5/8/2025 |
1.1.5-preview.1 | 109 | 5/6/2025 |
1.1.4 | 221 | 5/4/2025 |
1.1.4-preview.1 | 133 | 4/29/2025 |
1.1.3 | 794 | 4/27/2025 |
1.1.3-preview.1 | 114 | 4/22/2025 |
1.1.2-preview.1 | 154 | 4/14/2025 |
1.1.1-preview.17 | 89 | 4/11/2025 |
1.1.1-preview.16 | 134 | 4/7/2025 |
1.1.1-preview.15 | 124 | 4/1/2025 |
1.1.1-preview.14 | 119 | 4/1/2025 |
1.1.1-preview.13 | 131 | 3/20/2025 |
1.1.1-preview.12 | 49 | 3/15/2025 |
1.1.1-preview.11 | 135 | 3/11/2025 |
1.1.1-preview.10 | 72 | 2/17/2025 |
1.1.1-preview.9 | 71 | 2/16/2025 |
1.1.1-preview.8 | 75 | 2/15/2025 |
1.1.1-preview.7 | 75 | 2/12/2025 |
1.1.1-preview.6 | 72 | 2/3/2025 |
1.1.1-preview.5 | 71 | 1/17/2025 |
1.1.1-preview.4 | 57 | 1/13/2025 |
1.1.1-preview.3 | 69 | 12/18/2024 |
1.1.1-preview.2 | 64 | 11/29/2024 |
1.1.1-preview.1 | 60 | 11/16/2024 |
1.1.0 | 12,681 | 11/5/2024 |
1.0.3-preview.48 | 60 | 11/5/2024 |
1.0.3-preview.47 | 62 | 10/31/2024 |
1.0.3-preview.46 | 64 | 10/30/2024 |
1.0.3-preview.45 | 59 | 10/28/2024 |
1.0.3-preview.44 | 60 | 10/28/2024 |
1.0.3-preview.43 | 62 | 10/28/2024 |
1.0.3-preview.42 | 62 | 10/7/2024 |
1.0.3-preview.41 | 65 | 10/1/2024 |
1.0.3-preview.40 | 65 | 9/30/2024 |
1.0.3-preview.39 | 76 | 9/27/2024 |
1.0.3-preview.38 | 69 | 9/13/2024 |
1.0.3-preview.37 | 63 | 8/27/2024 |
1.0.3-preview.36 | 65 | 8/27/2024 |
1.0.3-preview.35 | 64 | 8/27/2024 |
1.0.3-preview.34 | 79 | 8/16/2024 |
1.0.3-preview.33 | 60 | 7/30/2024 |
1.0.3-preview.32 | 69 | 7/15/2024 |
1.0.3-preview.31 | 59 | 7/15/2024 |
1.0.3-preview.30 | 66 | 7/5/2024 |
1.0.3-preview.29 | 74 | 5/31/2024 |
1.0.3-preview.28 | 70 | 5/31/2024 |
1.0.3-preview.27 | 65 | 5/21/2024 |
1.0.3-preview.26 | 75 | 5/10/2024 |
1.0.3-preview.25 | 61 | 5/3/2024 |
1.0.3-preview.24 | 77 | 4/15/2024 |
1.0.3-preview.23 | 81 | 4/12/2024 |
1.0.3-preview.22 | 75 | 4/3/2024 |
1.0.3-preview.21 | 68 | 3/8/2024 |
1.0.3-preview.20 | 68 | 3/7/2024 |
1.0.3-preview.19 | 75 | 3/4/2024 |
1.0.3-preview.18 | 77 | 3/1/2024 |
1.0.3-preview.17 | 81 | 2/16/2024 |
1.0.3-preview.16 | 77 | 2/6/2024 |
1.0.3-preview.15 | 72 | 2/6/2024 |
1.0.3-preview.14 | 70 | 1/22/2024 |
1.0.3-preview.13 | 75 | 1/12/2024 |
1.0.3-preview.12 | 66 | 1/12/2024 |
1.0.3-preview.11 | 65 | 1/12/2024 |
1.0.3-preview.10 | 87 | 12/18/2023 |
1.0.3-preview.9 | 104 | 11/26/2023 |
1.0.3-preview.8 | 84 | 11/17/2023 |
1.0.3-preview.7 | 86 | 11/7/2023 |
1.0.3-preview.6 | 84 | 10/30/2023 |
1.0.3-preview.5 | 91 | 10/13/2023 |
1.0.3-preview.4 | 89 | 9/26/2023 |
1.0.3-preview.3 | 97 | 9/25/2023 |
1.0.3-preview.2 | 82 | 9/20/2023 |
1.0.3-preview.1 | 92 | 9/20/2023 |
1.0.2 | 36,938 | 7/20/2023 |
1.0.2-preview.14 | 104 | 7/20/2023 |