ManagedCode.IntegrationTestBaseKit.XUnit
0.0.2
Prefix Reserved
dotnet add package ManagedCode.IntegrationTestBaseKit.XUnit --version 0.0.2
NuGet\Install-Package ManagedCode.IntegrationTestBaseKit.XUnit -Version 0.0.2
<PackageReference Include="ManagedCode.IntegrationTestBaseKit.XUnit" Version="0.0.2" />
paket add ManagedCode.IntegrationTestBaseKit.XUnit --version 0.0.2
#r "nuget: ManagedCode.IntegrationTestBaseKit.XUnit, 0.0.2"
// Install ManagedCode.IntegrationTestBaseKit.XUnit as a Cake Addin #addin nuget:?package=ManagedCode.IntegrationTestBaseKit.XUnit&version=0.0.2 // Install ManagedCode.IntegrationTestBaseKit.XUnit as a Cake Tool #tool nuget:?package=ManagedCode.IntegrationTestBaseKit.XUnit&version=0.0.2
IntegrationTestBaseKit
Overview
IntegrationTestBaseKit is a library designed to facilitate the creation and management of Docker containers for integration testing purposes. It provides a set of tools to start, stop, and check the readiness of Docker containers in a thread-safe manner.
Features
- Start and stop Docker containers asynchronously.
- Check container readiness using customizable wait strategies.
- Event-driven notifications for container lifecycle events (starting, started, stopping, stopped).
Installation
To install the library, use the following command:
dotnet add package ManagedCode.IntegrationTestBaseKit
for xUnit integration use the following command:
dotnet add package ManagedCode.ManagedCode.IntegrationTestBaseKit.XUnit
Usage
Creating a Test Application
Define a TestApp class that inherits from BaseXUnitTestApp<TestBlazorApp.Program>
, add ICollectionFixture<TestApp>
using DotNet.Testcontainers.Containers;
using Testcontainers.Azurite;
using Testcontainers.PostgreSql;
using Xunit;
namespace ManagedCode.IntegrationTestBaseKit.Tests
{
[CollectionDefinition(nameof(TestApp))]
public class TestApp : BaseXUnitTestApp<TestBlazorApp.Program>, ICollectionFixture<TestApp>
{
protected override async Task ConfigureTestContainers()
{
AddContainer(new AzuriteBuilder().Build());
AddContainer("postgree", new PostgreSqlBuilder().Build());
}
}
}
Writing Tests
Use the TestApp class in your tests to manage Docker containers.
using DotNet.Testcontainers.Containers;
using FluentAssertions;
using Testcontainers.Azurite;
using Testcontainers.PostgreSql;
using Xunit.Abstractions;
namespace ManagedCode.IntegrationTestBaseKit.Tests;
[Collection(nameof(TestApp))]
public class HealthTests(ITestOutputHelper log, TestApp testApplication)
{
[Fact]
public async Task HealthTest()
{
var client = testApplication.CreateHttpClient();
var response = await client.GetAsync("/health");
response.EnsureSuccessStatusCode();
}
[Fact]
public async Task BrowserHealthTest()
{
var page = await testApplication.OpenNewPage("/health");
var content = await page.ContentAsync();
content.Contains("Healthy")
.Should()
.BeTrue();
}
[Fact]
public async Task HealthTest()
{
var client = testApplication.CreateSignalRClient("/healthHub");
await client.StartAsync();
client.State
.Should()
.Be(HubConnectionState.Connected);
var result = await client.InvokeAsync<string>("Health");
result.Should()
.Be("Healthy");
}
}
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
- ManagedCode.ManagedCode.IntegrationTestBaseKit (>= 0.0.2)
- Microsoft.AspNetCore.Mvc.Testing (>= 8.0.8)
- Microsoft.AspNetCore.SignalR.Client (>= 8.0.8)
- Microsoft.NET.Test.Sdk (>= 17.11.0)
- Microsoft.Playwright (>= 1.46.0)
- Microsoft.TestPlatform.TestHost (>= 17.11.0)
- Testcontainers (>= 3.9.0)
- xunit (>= 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.