| name | integration-testing |
| description | Guidelines for cross-layer testing (Hooks + UI + Services) using real logic and MSW for network interception. |
Integration Testing Skill (BackEnd)
This skill defines how to implement and organize integration tests that validate the interaction between Endpoints, Services, and the Database.
Core Principle: "Real Logic & Infrastructure"
Unlike unit tests that mock dependencies, integration tests in FinanzApp Backend use:
- Real Controllers: Calls to
WebAPI/Endpoints/ are executed via HttpClient.
- Real Services: Business logic in
Services/ is executed fully.
- WebApplicationFactory: Spin up a test server in memory to handle real API requests.
- In-Memory DB / SQLite: Use a lightweight DB provider to test persistence without external SQL Server dependency.
- Mocked Third-Party APIs: Use
Moq or a mock server (like WireMock.Net) to intercept external calls (CoinGecko, Yahoo Finance).
Organization
All integration tests MUST be located in the global tests directory:
- Path:
Tests/Integration/[Module]/[Feature]IntegrationTests.cs
Guidelines
- Scope: Test full business flows (e.g., Create Operation -> Calculate Portfolio Valuations -> Verify DB Persisted).
- External Mocks: Isolate external infrastructure (Mail, Storage, AI) using
Moq while keeping core internal logic untouched.
- State Management: Ensure the database is reset or uses a fresh directory/name between test runs to ensure isolation.
- Auth Simulation: Use a custom
AuthenticationHandler or a test JWT generator to simulate authenticated requests.
Example
[Fact]
public async Task Login_ValidCredentials_ReturnsTokenAndUser()
{
var client = _factory.CreateClient();
var loginDto = new LoginDto { Email = "test@example.com", Password = "Password123" };
var response = await client.PostAsJsonAsync("/api/auth/login", loginDto);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<LoginResultDto>();
Assert.NotNull(result.Token);
Assert.Equal("Agus", result.User.Name);
}