Requirements - green-ecolution/backend GitHub Wiki
Introduction
Well-written tests are essential to ensure stability when introducing new features or refactoring code, detect bugs early and ensure that each layer behaves correctly on its own and as part of the full system.
Before writing or running tests, itโs important to understand the technical setup behind each layer. This section explains what tools, dependencies and conventions are required depending on where the code lives.
General
To run and write backend tests, make sure the following are in place:
- Go environment set up (Go version as defined in the
go.mod
file) - Use of
testify/assert
for expressive assertions - Use of test suite helpers for setup/cleanup where applicable
Storage Layer
- Requires Docker, since the tests use Testcontainers to spin up:
- Uses a real PostgreSQL database
- A Keycloak instance for authentication testing
- Reset DB and seed data using helpers:
suite.ResetDB()
suite.InsertSeed(...)
Service Layer
- No Docker required
- Tests use mocked repositories (via
/storage/_mock
) - Mocks are defined using a mocking library
Server Layer
- No Docker required
- If your handlers call services, you can use mocks to isolate handler logic.
- You should use Fiber for consistency and clarity:
app := fiber.New()