ASP.NET Core MVC Interview Question #154

What is integration testing in ASP.NET Core MVC?

Testing, AJAX/JavaScript Integration, Localization & Advanced MVC Senior Advanced

Quick Interview Answer

Integration testing exercises multiple application components together through a realistic ASP.NET Core request pipeline. It can verify routing, middleware, filters, model binding, authorization, controller execution, dependency injection, and HTTP responses.

Detailed Explanation

Integration testing exercises multiple application components together through a realistic ASP.NET Core request pipeline. It can verify routing, middleware, filters, model binding, authorization, controller execution, dependency injection, and HTTP responses.

ASP.NET Core's test-hosting infrastructure can run the application in memory without requiring a separately deployed web server, making integration tests valuable for endpoint behavior that cannot be represented accurately by direct controller calls.

Code Example

public class ProductsTests
    : IClassFixture<WebApplicationFactory<Program>>
{
    private readonly HttpClient _client;

    public ProductsTests(
        WebApplicationFactory<Program> factory)
    {
        _client = factory.CreateClient();
    }
}