ArwynFr.IntegrationTesting
0.3.10
dotnet add package ArwynFr.IntegrationTesting --version 0.3.10
NuGet\Install-Package ArwynFr.IntegrationTesting -Version 0.3.10
<PackageReference Include="ArwynFr.IntegrationTesting" Version="0.3.10" />
paket add ArwynFr.IntegrationTesting --version 0.3.10
#r "nuget: ArwynFr.IntegrationTesting, 0.3.10"
// Install ArwynFr.IntegrationTesting as a Cake Addin #addin nuget:?package=ArwynFr.IntegrationTesting&version=0.3.10 // Install ArwynFr.IntegrationTesting as a Cake Tool #tool nuget:?package=ArwynFr.IntegrationTesting&version=0.3.10
ArwynFr.IntegrationTesting
This library provides utility classes for writing integration tests in
dotnet using XUnit
and WebApplicationFactory
.
Installation
dotnet new classlib -n MyTestProject
dotnet add package ArwynFr.IntegrationTesting
dotnet add package Microsoft.NET.Test.Sdk
dotnet add package xunit.runner.visualstudio
Usage
Read advanced usage documentation for further details.
By default, the lib redirects the tested application logs to XUnit output, so you get them in the test output in case of failure. It also overwrites the application configuration with values from user secrets and environement variables.
public class MyTest(ITestOutputHelper output) : IntegrationTestBase<Program>(output)
{
// Override a service with fake implementation in the tested app
protected override void ConfigureAppServices(IServiceCollection services)
=> services.AddSingleton<IMyService, FakeService>();
[Fact]
public async Task OnTest()
{
// Call system under test
var response = await Client.GetFromJsonAsync<OrderDto>($"/order");
response.Should().HaveValue();
}
}
EntityFrameworkCore integration
If your application uses EFcore, add the DbContext as a generic parameter and provide a configuration method. You can override the DbContext lifetime strategy according to your needs:
public class TestBaseDb(ITestOutputHelper output) : IntegrationTestBase<Program, MyDbContext>(output)
{
// Create and drop a database for every test execution
protected override IDatabaseTestStrategy<Context> DatabaseTestStrategy
=> IDatabaseTestStrategy<MyDbContext>.DatabasePerTest;
// Configure EFcore with a random database name par test
protected override void ConfigureDbContext(DbContextOptionsBuilder builder)
=> builder.UseSqlite($"Data Source={Guid.NewGuid()}.sqlite");
[Fact]
public async Task OnTest()
{
// Access the injected dbcontext
var value = await Database.Values
.Where(val => val.Id == 1)
.Select(val => val.Result)
.FirstOrDefaultAsync();
// Call system under test
var result = await Client.GetFromJsonAsync<int>("/api/value/1");
result.Should().Be(value + 1);
}
}
OpenTelemetry integration
You can access OTEL activities produced by your application in your tests. This requires you to list which activities to monitor:
public class OpenTelemetryTests(ITestOutputHelper output) : IntegrationTestBase<Program>(output)
{
// Tell the library which OTEL sources you want to monitor
// Traces from other sources will be ignored
protected override string[] OpenTelemetrySourceNames => ["SourceA", "SourceB"];
[Fact]
public async Task Otel()
{
// Call system under test
await Client.GetAsync("/otel");
// Assert on the collection of all activities collected
Activities.Any(activity => activity.DisplayName == "Hello").Should().BeTrue();
}
}
Contributing
This project welcomes contributions:
Request for support:
We do not provide commercial support for this product.
Disclose vulnerability:
Read our security policy
Create a new security advisory on GitHub
Report malfunctions:
Create a new issue on GitHub
Suggest a feature:
Create a new issue on GitHub
Offer some code:
Read our definition of done
Fork the repository
Submit a pull-request
Moderate contributions:
Read our governance policy
This project is not currently appointing new moderators.
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. |
-
net8.0
- Microsoft.AspNetCore.Mvc.Testing (>= 8.0.8)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.8)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- OpenTelemetry.Exporter.InMemory (>= 1.9.0)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.9.0)
- XUnit (>= 2.9.2)
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 |
---|---|---|
0.3.10 | 103 | 9/27/2024 |
0.3.9 | 92 | 9/25/2024 |
0.3.8 | 84 | 9/23/2024 |
0.3.7 | 133 | 9/16/2024 |
0.3.6 | 104 | 9/10/2024 |
0.3.5 | 105 | 9/9/2024 |
0.3.4 | 112 | 9/5/2024 |
0.3.3 | 134 | 8/23/2024 |
0.3.2 | 117 | 8/20/2024 |
0.3.1 | 122 | 8/17/2024 |
0.3.0 | 138 | 8/16/2024 |
0.2.41 | 112 | 8/16/2024 |
0.2.40 | 127 | 8/14/2024 |
0.2.39 | 127 | 8/13/2024 |
0.2.37 | 103 | 8/7/2024 |
0.2.35 | 101 | 7/9/2024 |
0.2.34 | 121 | 7/8/2024 |
0.2.33 | 113 | 6/26/2024 |
0.2.32 | 101 | 6/26/2024 |
0.2.31 | 104 | 6/18/2024 |
0.2.30 | 108 | 6/14/2024 |
0.2.29 | 89 | 6/7/2024 |
0.2.28 | 107 | 6/2/2024 |
0.2.27 | 92 | 5/22/2024 |
0.2.26 | 114 | 5/17/2024 |
0.2.25 | 105 | 5/16/2024 |
0.2.24 | 107 | 5/16/2024 |
0.2.23 | 116 | 5/15/2024 |
0.2.22 | 106 | 5/15/2024 |
0.2.21 | 99 | 5/15/2024 |
0.2.20 | 118 | 5/14/2024 |
0.2.19 | 93 | 5/13/2024 |
0.2.18 | 138 | 4/28/2024 |
0.2.17 | 103 | 4/24/2024 |
0.2.16 | 112 | 4/18/2024 |
0.2.15 | 92 | 4/17/2024 |
0.2.14 | 89 | 4/17/2024 |
0.2.12 | 103 | 4/12/2024 |
0.2.11 | 122 | 4/12/2024 |
0.2.10 | 123 | 4/10/2024 |
0.2.9 | 98 | 4/8/2024 |
0.2.8 | 104 | 4/8/2024 |
0.2.7 | 131 | 3/15/2024 |
0.2.6 | 132 | 3/15/2024 |
0.2.5 | 123 | 3/6/2024 |
0.2.4 | 123 | 2/24/2024 |
0.2.3 | 108 | 2/16/2024 |
0.2.2 | 126 | 2/14/2024 |
0.2.1 | 137 | 2/8/2024 |
0.2.0 | 120 | 2/2/2024 |
0.1.2 | 119 | 1/30/2024 |
0.1.1 | 114 | 1/30/2024 |
0.1.0 | 118 | 1/26/2024 |