WebApi — Integration Test — Digitteck
WebApi — Integration Test
dotnet·29 June 2020·2 min read

WebApi — Integration Test

Integration tests verify that an application's components work together correctly and that business logic returns expected values. WebApplicationFactory spins up the actual host in-process during tests, providing a real HTTP client connected to it — no mocking required.

Start with the default WebApi template — this example uses the weather forecast controller generated by Visual Studio:

Default WebApi project template

Create an NUnit test project and install the Microsoft.AspNetCore.Mvc.Testing NuGet package:

Installing Microsoft.AspNetCore.Mvc.Testing

Create a WebApplicationFactory subclass in the test project — this starts the API host and exposes an HttpClient connected to it:

WebApplicationFactory setup in test project

Use the factory's client to make real HTTP calls against the running API:

NUnit test method using the HttpClient

Tags

.NETASP.NET CoreTesting
digitteck

© 2026 Digitteck