Creating .NET Aspire integration tests
While unit tests should be the primary tests, integration tests not only test a small functionality but include testing of multiple components within one test, such as including infrastructure – for example, a database.
.NET Aspire contains a library and test templates using xUnit, which easily allows creating integration tests to directly access the app model.
Let’s create a .NET Aspire test project using .NET Aspire and xUnit, named Codebreaker.IntegrationTests
:
dotnet new aspire-xunit -o Codebreaker.IntegrationTests
This project includes references to the Aspire.Hosting.Testing
NuGet package, as well as Microsoft.NET.Test.Sdk
, xUnit, and xunit.runner.visualstudio
. To allow accessing the app model, add a project reference to Codebreaker.AppHost
. With the integration test we implement, we need types from the game APIs project, thus we also add a reference to Codebreaker.GameAPIs
.