opcotech/elemo

View on GitHub
docs/ADRs/0017.test-file-naming.md

Summary

Maintainability
Test Coverage
# Test File Naming

| author       | created at | updated at | status   |
|:-------------|:-----------|------------|:---------|
| @gabor-boros | 2023-05-13 | -          | accepted |

## Abstract

We need a convention for naming test files on the long run to keep the naming
consistent and easy to understand. This ADR proposes a convention for naming
test files. The convention is based on the Go test file naming
convention, but extended with some rules.

We need to think about unit tests, integration tests, end-to-end tests, load
tests, etc. The convention should be applicable for all of them.

## Decision

We split the tests based on their location into four groups:

- backend tests
- front-end tests
- end-to-end tests
- load tests

Backend tests are located in the `internal` and/or `pkg` directories. Front-end
and end-to-end tests that are clicking through the UI are located in the `web`
directory. The rest of the end-to-end tests and load tests are located in the 
`tests` directory of the project root.

Except for load tests, all tests should follow the `*_test.<extension>` naming
convention. Backend tests can break the `*_test.go` naming convention if the
test is an integration test. In this case, the test file should be named as
`*_integration_test.go` and located next to the tested file.

The load tests are not restricted to the `*_test.go` naming convention, due to
the nature of k6 tests. For load tests, we want to have test scenarios, so the
rule of thumb is to have a meaningful name for the scenario instead of the
`*_test.go` naming convention.

In case of backend tests, the test file should be located next to
the tested file. In case of front-end and end-to-end tests, the test file
should be located next to the tested file or in a subdirectory named `tests`.

## Consequences

The test file naming convention is consistent and easy to understand.

## References

None.