Rationale

Unit tests are the foundation of test pyramids. GitLab requires adequate unit test coverage to catch regressions early.

Requirements

  1. New code must have >= 80% unit test coverage
  2. Overall project coverage must not decrease
  3. Critical business logic paths must have 100% coverage
  4. 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

References