Workleap.Extensions.Xunit
1.0.3-preview.37
Prefix Reserved
See the version list below for details.
dotnet add package Workleap.Extensions.Xunit --version 1.0.3-preview.37
NuGet\Install-Package Workleap.Extensions.Xunit -Version 1.0.3-preview.37
<PackageReference Include="Workleap.Extensions.Xunit" Version="1.0.3-preview.37" />
paket add Workleap.Extensions.Xunit --version 1.0.3-preview.37
#r "nuget: Workleap.Extensions.Xunit, 1.0.3-preview.37"
// Install Workleap.Extensions.Xunit as a Cake Addin #addin nuget:?package=Workleap.Extensions.Xunit&version=1.0.3-preview.37&prerelease // Install Workleap.Extensions.Xunit as a Cake Tool #tool nuget:?package=Workleap.Extensions.Xunit&version=1.0.3-preview.37&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. |
.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.9.0)
-
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.9.0)
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-preview.4 | 22 | 20 hours ago |
1.1.1-preview.3 | 50 | a month ago |
1.1.1-preview.2 | 50 | a month ago |
1.1.1-preview.1 | 46 | 2 months ago |
1.1.0 | 1,606 | 2 months ago |
1.0.3-preview.48 | 45 | 2 months ago |
1.0.3-preview.47 | 48 | 2 months ago |
1.0.3-preview.46 | 48 | 2 months ago |
1.0.3-preview.45 | 49 | 3 months ago |
1.0.3-preview.44 | 47 | 3 months ago |
1.0.3-preview.43 | 47 | 3 months ago |
1.0.3-preview.42 | 49 | 3 months ago |
1.0.3-preview.41 | 54 | 3 months ago |
1.0.3-preview.40 | 53 | 3 months ago |
1.0.3-preview.39 | 55 | 4 months ago |
1.0.3-preview.38 | 59 | 4 months ago |
1.0.3-preview.37 | 54 | 5 months ago |
1.0.3-preview.36 | 53 | 5 months ago |
1.0.3-preview.35 | 53 | 5 months ago |
1.0.3-preview.34 | 70 | 5 months ago |
1.0.3-preview.33 | 53 | 5 months ago |
1.0.3-preview.32 | 57 | 6 months ago |
1.0.3-preview.31 | 51 | 6 months ago |
1.0.3-preview.30 | 49 | 6 months ago |
1.0.3-preview.29 | 66 | 7 months ago |
1.0.3-preview.28 | 60 | 7 months ago |
1.0.3-preview.27 | 58 | 8 months ago |
1.0.3-preview.26 | 67 | 8 months ago |
1.0.3-preview.25 | 53 | 8 months ago |
1.0.3-preview.24 | 70 | 9 months ago |
1.0.3-preview.23 | 72 | 9 months ago |
1.0.3-preview.22 | 65 | 9 months ago |
1.0.3-preview.21 | 59 | 3/8/2024 |
1.0.3-preview.20 | 60 | 3/7/2024 |
1.0.3-preview.19 | 68 | 3/4/2024 |
1.0.3-preview.18 | 68 | 3/1/2024 |
1.0.3-preview.17 | 71 | 2/16/2024 |
1.0.3-preview.16 | 70 | 2/6/2024 |
1.0.3-preview.15 | 65 | 2/6/2024 |
1.0.3-preview.14 | 61 | 1/22/2024 |
1.0.3-preview.13 | 65 | 1/12/2024 |
1.0.3-preview.12 | 59 | 1/12/2024 |
1.0.3-preview.11 | 59 | 1/12/2024 |
1.0.3-preview.10 | 79 | 12/18/2023 |
1.0.3-preview.9 | 96 | 11/26/2023 |
1.0.3-preview.8 | 78 | 11/17/2023 |
1.0.3-preview.7 | 75 | 11/7/2023 |
1.0.3-preview.6 | 79 | 10/30/2023 |
1.0.3-preview.5 | 84 | 10/13/2023 |
1.0.3-preview.4 | 82 | 9/26/2023 |
1.0.3-preview.3 | 83 | 9/25/2023 |
1.0.3-preview.2 | 74 | 9/20/2023 |
1.0.3-preview.1 | 83 | 9/20/2023 |
1.0.2 | 30,026 | 7/20/2023 |
1.0.2-preview.14 | 91 | 7/20/2023 |