DevOps & CI/CDMedium30 XP4 min read
How do you run Flutter tests in a CI/CD pipeline?
TL;DR: Run 'flutter test --coverage' for unit/widget tests in CI. Integration tests need an emulator (uses-nix: macos-latest for iOS, ubuntu + emulator action for Android). Upload coverage to Codecov. Gate merges on passing tests with branch protection rules.
Full Answer
Testing Pyramid in CI
- ▸Unit/widget tests: 'flutter test --coverage' — fast, no emulator, run on every PR
- ▸Golden tests: 'flutter test --update-goldens' — screenshot regression tests, run on schedule
- ▸Integration tests: need a real device/emulator — run on merge to main or nightly
- ▸Coverage: upload lcov.info to Codecov, set minimum 80% threshold
🎯
Split CI jobs: fast tests (unit/widget) on every push, slow tests (integration) only on main branch merges. This keeps PR feedback under 3 minutes.
Code Examples
yamlComplete Flutter CI pipeline
Output
// PR: runs test + analyze (~2-3 min) // main merge: test + build android bundle // Coverage gated at 80% minimum
Common Mistakes
- ✗Running integration tests on every PR — too slow, blocks developer velocity
- ✗No coverage gate — coverage drifts to 0% without enforcement
Interview Tip
💡
Show the split: fast tests on every PR, slow integration tests on main. Also mention flutter analyze — it catches type errors and style issues before tests run, failing fast.
#CI/CD#testing#github-actions#coverage#integration-tests