📚 Encyclopedia

Flutter & Mobile · updated 2026-10-13

Testing Flutter/Flame games and running them in GitLab CI

fluttertestingflame-testmocktailgladosproperty-testinggitlab-cipre-commit

A practical test stack for a Flutter game, what to test first, and the GitLab CI and git-hook setup Run uses (tests grew from 0 to 170 between 2026-03 and 2026-10).

Stack

What to test first (value per effort)

  1. Pure physics (MovementSystem with no engine deps): plain unit tests.
  2. Simulations (liquid automata): property tests for invariants (velocity caps, bounds, collision symmetry, mass conservation).
  3. Hazard and ability logic via testWithFlameGame.
  4. Golden tests for themes/backgrounds (avoid text: fonts differ across platforms; goldens need xvfb in headless CI).
  5. Serialization round trips: build every entity with non-default values, serialize, parse, compare; plus a golden parse of every built-in level. This catches the "forgotten field" class (Game content data models (stable ids, schemas, serialization)). Extract math into pure static functions so it can be tested (Run's editor panBy/zoomAbout had a double-counted pinch until unit-tested). A sensible coverage target for a game is 30-50%, focused on logic, not rendering.

Gotchas

Local hooks

A pre-commit hook runs dart format on staged files and flutter analyze --no-pub, blocking on errors (not on info lints). A Claude Code PreToolUse hook meant to run an architect review before git commit never effectively blocked anything: with a 10 s timeout and no permissionDecision: "ask" the commit was simply allowed. Review agents are run manually (/review) instead.

GitLab CI

See also

Linked from

Sources: run memory (research-testing-cicd.md, session-v053-v057.md, session-v065-v075.md, feedback-pipeline-check-before-push.md, improvement-cycles.md, mobile-shell.md, session-v085.md)