CI/CD for a Flutter integration_test App with GitHub Actions
Run analyzer and widget tests fast, then integration_test on an emulator.
Flutter integration_test drives the full app on a device or emulator, complementing fast widget tests. This recipe runs analyzer and widget tests on Linux, then integration tests on an Android emulator.
What the pipeline does
- set up Flutter with caching
- run flutter analyze
- run widget tests with flutter test
- boot an Android emulator
- run integration_test on the emulator
The workflow
Fast checks run on ubuntu-latest. The integration job uses reactivecircus/android-emulator-runner, which needs nested virtualization, to boot an emulator and run the integration suite.
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
- run: flutter pub get
- run: flutter analyze
- run: flutter test
integration:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
- run: flutter pub get
- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
arch: x86_64
script: flutter test integration_testCaching and speed
flutter-action cache: true restores the Flutter SDK and pub cache; the emulator action caches AVD snapshots so boots are faster. Emulator boots are slow and heavy, so cheaper managed runners such as Latchkey (around 69% cheaper than GitHub-hosted) keep the integration job affordable, and auto-retry covers a flaky emulator boot.
Deploying
After tests pass, build the artifact: flutter build appbundle for Android (sign and upload to Play) or flutter build ipa on a macOS runner for iOS. Hand off distribution to fastlane or the store consoles.
Key takeaways
- Split fast widget tests from slow emulator-backed integration tests.
- Use android-emulator-runner with AVD caching for integration_test.
- flutter-action caches the SDK and pub cache.