ASP.NET Core Interview Question #203

What is WebApplicationFactory<TEntryPoint>?

Testing, Deployment & Hosting Senior Advanced

Quick Interview Answer

WebApplicationFactory<TEntryPoint> is a testing utility from Microsoft.AspNetCore.Mvc.Testing that creates an ASP.NET Core application host for functional and integration tests.

Detailed Explanation

WebApplicationFactory<TEntryPoint> is a testing utility from Microsoft.AspNetCore.Mvc.Testing that creates an ASP.NET Core application host for functional and integration tests.

It can create HttpClient instances that communicate with the in-memory test server. The factory can also be customized to replace services, configuration, authentication, or database registrations for the test environment.

This allows tests to exercise much of the real application pipeline without deploying to an external web server.

Code Example

await using var factory =
    new WebApplicationFactory<Program>();

var client = factory.CreateClient();

var response = await client.GetAsync("/health");