Rationale
Unit tests are the foundation of test pyramids. GitLab requires adequate unit test coverage to catch regressions early.
Requirements
- New code must have >= 80% unit test coverage
- Overall project coverage must not decrease
- Critical business logic paths must have 100% coverage
- Unit tests must be fast (< 10ms per test)
Coverage Metrics
| Metric | Threshold |
|---|---|
| Line coverage | >= 80% |
| Branch coverage | >= 75% |
| Method coverage | >= 80% |
Test Quality Standards
- Each test must verify one behavior (Single Assertion Principle)
- Tests must be deterministic (no flaky tests)
- Test names must describe the scenario:
should_<expected>_when_<condition> - Use meaningful test data, not mocks where real objects work