.NET

Integration Testing

WebApplicationFactory, TestServer, database testing, HTTP client testing, test fixtures

18 pytań z rozmów·
Mid-Level
1

What is WebApplicationFactory in ASP.NET Core?

Odpowiedź

WebApplicationFactory is a class provided by the Microsoft.AspNetCore.Mvc.Testing package that allows creating an in-memory test server for integration testing. It initializes the ASP.NET Core application with all its dependencies without requiring actual deployment, making tests fast and isolated. This approach is recommended because it tests the application in an environment close to production while avoiding the setup costs of a real server.

2

What is the main advantage of using WebApplicationFactory instead of a real HTTP server in integration tests?

Odpowiedź

WebApplicationFactory creates an in-memory test server, which eliminates network latency and deployment costs while providing full control over configuration. Tests execute much faster because there's no real network communication or separate process to manage. Additionally, services can be replaced via ConfigureTestServices, which facilitates test isolation and simulation of different scenarios without external infrastructure.

3

What is the difference between a unit test and an integration test in ASP.NET Core?

Odpowiedź

Unit tests isolate and test a single unit of code (method, class) by mocking all dependencies, while integration tests verify that multiple components work together correctly, including the database, middleware, and real services. Unit tests are faster and simpler but don't detect integration issues, while integration tests are slower but validate the application's overall behavior. A balanced strategy combines both approaches.

4

Which NuGet package is required to use WebApplicationFactory in integration tests?

5

How to create an HTTP client to test an API with WebApplicationFactory?

+15 pytań z rozmów

Opanuj .NET na następną rozmowę

Uzyskaj dostęp do wszystkich pytań, flashcards, testów technicznych, ćwiczeń code review i symulatorów rozmów.

Zacznij za darmo