Flutter Testing

Framework Configuration

Key Requirements

  • Coverage report must be in LCOV format
  • Report must be saved as coverage/lcov.info
  • Report must be uploaded as a GitHub Actions artifact named coverage-report

Flutter's built-in test framework can generate LCOV coverage reports.

pubspec.yaml
dev_dependencies:
  flutter_test:
    sdk: flutter

Setting Up GitHub Actions

Create a workflow file in .github/workflows/ directory. The filename can be anything you prefer (e.g. flutter-coverage.yml). Add the following content to your workflow file:

flutter-coverage.yml
name: Flutter Coverage

on:
  push:
  workflow_dispatch:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: "stable"

      - name: Install dependencies
        run: flutter pub get

      - name: Run tests with coverage
        run: flutter test --coverage

      - name: Upload coverage report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: coverage/lcov.info

Key Configuration Points

  • Run tests with --coverage flag
  • Upload the report as an artifact named coverage-report
  • Ensure the report is saved as coverage/lcov.info

Viewing Coverage Reports

After your workflow runs successfully, GitAuto automatically processes the coverage reports and displays them in the Coverage Dashboard. The data updates whenever:

  • You push to any branch (except master)
  • You push additional commits to a pull request
  • You manually trigger the workflow

About LCOV: LCOV (Linux Code Coverage) is a standard format for code coverage data. It's pronounced "el-cov" and is widely supported by various tools and services.