AspNetCore.Docs/aspnetcore/fundamentals/minimal-apis/test-min-api.md

2.2 KiB

title author description ms.author ms.date monikerRange uid
Test Minimal API apps rick-anderson Unit and integration tests in Minimal API apps wpickett 05/31/2024 >= aspnetcore-7.0 fundamentals/minimal-apis/test-min-api

Unit and integration tests in Minimal API apps

[!INCLUDE]

By Fiyaz Bin Hasan, and Rick Anderson

[!INCLUDE]

The sample code on GitHub provides an example of unit and integration tests on a Minimal API app.

IResult implementation types

Public xref:Microsoft.AspNetCore.Http.IResult implementation types in the xref:Microsoft.AspNetCore.Http.HttpResults?displayProperty=fullName namespace can be used to unit test minimal route handlers when using named methods instead of lambdas.

The following code uses the NotFound<TValue> class:

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/minimal-apis/samples/MinApiTestsSample/UnitTests/TodoInMemoryTests.cs" id="snippet_" highlight="8":::

The following code uses the Ok<TValue> class:

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/minimal-apis/samples/MinApiTestsSample/UnitTests/TodoInMemoryTests.cs" id="snippet_1" highlight="18":::

Additional Resources