Integration Testing

Overview

Integration testing validates interactions between components such as API layers, databases, queues, and external services.

Scope

sequenceDiagram participant Test participant API participant DB Test->>API: POST /orders API->>DB: insert order DB-->>API: success API-->>Test: 201 Created

Practical Example

public class OrdersApiTests : IClassFixture<ApiTestFactory> { private readonly HttpClient _client; public OrdersApiTests(ApiTestFactory factory) { _client = factory.CreateClient(); } [Fact] public async Task CreateOrder_ReturnsCreated() { var payload = new { customerId = "cust-1", total = 149.90m }; var response = await _client.PostAsJsonAsync("/orders", payload); Assert.Equal(HttpStatusCode.Created, response.StatusCode); } }

Integration tests run against real dependencies in controlled environments.

Production Guidance

Common Pitfalls

Key Takeaways