Add backend test suite: service unit tests, repository tests, controller slice tests #4
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Establish a meaningful backend test suite covering the three layers with the highest ROI. The existing e2e tests cover the full stack — these tests fill in the gaps at the unit and slice level.
Layer 1: Service unit tests (highest priority)
Test business logic in isolation using Mockito to mock repositories.
Candidates:
DocumentService— search filter logic, status transitions, tag cascade deletePersonService— find-or-create by alias, merge logicTagService— find/create, delete cascadeMassImportService— import parsing, error handling, duplicate detectionFileService— upload/download error handlingPattern:
Layer 2: Repository tests (
@DataJpaTest)Test non-trivial queries against a real database schema. Use Testcontainers with PostgreSQL (not H2) to stay close to production.
Candidates:
DocumentRepository— search query (filters by sender, receiver, tags, date range, full-text)Layer 3: Controller slice tests (
@WebMvcTest)Test the HTTP layer with a mocked service. Focus on auth/permission enforcement and response codes — not business logic.
Candidates for each controller:
401when no session403when insufficient permissions (@RequirePermission)400for missing/invalid required fields200/201happy path (response shape)Out of scope
Full
@SpringBootTestintegration tests — the e2e CI job already covers the full stack.marcel referenced this issue2026-04-25 17:00:44 +02:00