Skip to main content

Overview

Gitea has a comprehensive test suite covering unit tests, integration tests, and end-to-end tests. All contributions should include tests.

Running Tests

All Tests

Run the complete test suite:

Specific Test Packages

Run tests for a specific package:

Database-Specific Tests

Test Types

Unit Tests

Unit tests focus on individual functions and methods:

Integration Tests

Integration tests verify interactions between components:

End-to-End Tests

E2E tests use Playwright for browser automation:

Writing Tests

Test Structure

Organize tests following Go conventions:

Test Naming

Using Test Helpers

Gitea provides test utilities:

Test Database Setup

Test Coverage

Generate Coverage Report

Coverage Requirements

  • New code should have at least 80% coverage
  • Critical paths (authentication, permissions) should have near 100% coverage
  • Edge cases and error conditions should be tested

Continuous Integration

Tests run automatically on:
  • Every pull request
  • Commits to main branch
  • Nightly builds

CI Test Matrix

Tests run across multiple:
  • Go versions: 1.26.x
  • Databases: SQLite, PostgreSQL, MySQL, MSSQL
  • Operating systems: Linux, macOS, Windows
  • Architectures: amd64, arm64

Benchmarking

Run Benchmarks

Writing Benchmarks

Testing Best Practices

Write Clear Tests

  • Use descriptive test names
  • One assertion per test when possible
  • Clear arrange-act-assert structure

Test Edge Cases

  • Empty inputs
  • Nil values
  • Boundary conditions
  • Error scenarios

Keep Tests Fast

  • Mock external dependencies
  • Use table-driven tests
  • Avoid unnecessary sleeps

Make Tests Deterministic

  • Don’t rely on timing
  • Use fixed test data
  • Clean up after tests

Debugging Tests

Verbose Output

Debugging with Delve

Test Logs

Troubleshooting

Ensure test database is properly initialized:
Increase timeout for slow tests:
Run tests with race detector:

See Also

Contributing

Learn about the contribution process

Building

Build Gitea from source

Architecture

Understand the codebase structure