What to test - green-ecolution/backend GitHub Wiki

Introduction

Each layer has different responsibilities and therefore different things to test. This section gives you an overview of what kind of logic, behavior, and edge cases should be covered in Storage, Service, and Server tests.
Even if files are not part of a layer, if they perform important tasks, they should still be tested.

Storage Layer

  • Database operations (CRUD)
  • Data relationships and foreign keys (e.g. Tree ↔ TreeCluster)
  • Transactions and rollback behavior
  • Handling of constraint violations
  • Behavior when context is canceled

Service Layer

  • Core business logic
  • Correct use of repository interfaces
  • Aggregation and calculation logic
  • Behavior on repository errors (error handling/fail paths)

Server Layer

  • HTTP routing and endpoint behavior
  • Request validation (e.g. query params, body data)
  • Response formats and status codes
  • Middleware behavior (e.g. pagination)
  • Reactions to invalid or missing input