본문으로 건너뛰기
cccskills
무료GitHub에 공개

flutter-testing

Use when testing Flutter code - unit tests for logic, widget tests for UI behavior, golden tests for appearance, the multi-size/text-scale/dark matrix, accessibility guidelines, test-first

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md4.9 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Flutter Testing

Overview

Test-first in Flutter (see tdd-workflow). Three layers, each for a different question: does the logic work, does the widget behave, does it look right.

Core principle: Most tests are fast unit + widget tests. Golden tests guard appearance; integration tests guard whole flows — use them sparingly.

Test layers

LayerQuestionTool
UnitDoes the controller/logic compute correctly?flutter_test, mock the repository
WidgetDoes the widget render state and respond to taps?testWidgets + pumpWidget + finders
GoldenDoes it match the approved pixels?matchesGoldenFile
IntegrationDoes the whole flow work on a device?integration_test

Widget test example

testWidgets('shows error view and retries', (tester) async {
  final controller = FakeTaskController()..emitError('boom');
  await tester.pumpWidget(wrap(TaskListScreen(controller: controller)));
  await tester.pump();

  expect(find.text('boom'), findsOneWidget);
  await tester.tap(find.byType(RetryButton));
  await tester.pump();
  expect(controller.loadCalled, isTrue);   // intent reached the controller
});

Rules

  • Unit-test controllers/logic without pumping a widget — that's the payoff of keeping logic out of widgets (see flutter-state-management).
  • Widget tests assert observable behavior (text visible, tap triggers intent), not internal structure.
  • Mock the repository/ports, not the widget under test. Prefer a hand-written fake or mocktail per the app's convention.
  • Golden tests: commit the golden, review changes deliberately; regenerate only when the change is intended.
  • Cover loading, data, empty, and error states — the branches most likely to ship broken.
  • pump vs pumpAndSettle: use pump for controlled frames, pumpAndSettle to drain animations — never rely on real timers.

Matrix test: size, text scale, dark mode

A widget test that only runs at the default size and text scale misses the most common mobile layout bug — overflow at larger text scales. See mobile-visual-self-review for the full size matrix and the worked PriceRow example (verified: passes at text scale 1.0 everywhere, overflows by 82px at 360×640/2.0). The shape:

tester.view.physicalSize = const Size(360, 640) * 3;
tester.view.devicePixelRatio = 3;
tester.platformDispatcher.textScaleFactorTestValue = 2.0;
addTearDown(tester.view.reset);
addTearDown(tester.platformDispatcher.clearAllTestValues);

Run this as a real testWidgets case per matrix cell for any screen/component whose layout changed — it is the failing test a layout change starts from (see tdd-first), not an afterthought bolted on once the happy path passes.

Accessibility guidelines (verified)

meetsGuideline from flutter_test/flutter/accessibility, run inside tester.ensureSemantics():

final handle = tester.ensureSemantics();
await expectLater(tester, meetsGuideline(androidTapTargetGuideline));   // 48x48
await expectLater(tester, meetsGuideline(iOSTapTargetGuideline));       // 44x44
await expectLater(tester, meetsGuideline(labeledTapTargetGuideline));   // every tappable has a label
await expectLater(tester, meetsGuideline(textContrastGuideline));
handle.dispose();

Run these against every new or changed interactive widget's test, not just a dedicated accessibility suite.

Golden test pitfalls (verified)

  • Fonts: by default, text renders as box glyphs in a golden unless the app's real fonts are loaded in flutter_test_config.dart (loadAppFonts() or equivalent) — a golden taken without that setup locks in boxes, not the real typography. Use goldens for layout/shape verification, or load the fonts first.
  • OS differences: text rendering and anti-aliasing differ per OS, so the same golden can legitimately differ on macOS vs Linux CI. Tag golden tests (@Tags(['golden'])) and generate/update them on one OS consistently (match CI's).
  • Never --update-goldens to make a red test green without looking at the diff first — that silently accepts a visual regression as the new baseline.

Common Mistakes

  • pumpWidget for logic that could be a plain unit test (slow, indirect).
  • Asserting widget-tree internals instead of visible behavior.
  • No error/empty-state test.
  • Golden files regenerated blindly, hiding a visual regression.
  • A layout test that only runs at the default device size and text scale 1.0.

Red Flags

  • The test passes before the production code exists (tests a fake).
  • Every test boots the full app.
  • Only the happy path is covered.
  • No test exercises text scale 2.0 on a screen that changed layout.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Use when writing acceptance criteria for a task - express each as an observable Given/When/Then that QA can execute, including negative cases

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 18일 업데이트

Use when the diff adds or changes an endpoint, resolver, RPC, job or query that takes an object id, a role check, a request binding or a tenant filter - BOLA/IDOR, function-level authorization, mass assignment and tenant scoping

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 18일 업데이트

Use on every UI change - semantic HTML, labels for controls, keyboard-navigable dialogs/menus, visible focus, and never color as the only signal

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 18일 업데이트

Use when a task changes any screen, form, dialog, menu or control - Lighthouse/axe scan of the changed screens, a keyboard walk, and the thresholds that fail a task

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 18일 업데이트

How to work a task returned with review, QA or UAT findings. Use when a task is in need_revision or PR review comments are in your context.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 18일 업데이트

Use when the repository keeps its alerting in code, or a person asks for alerts outside TaskTrooper - PrometheusRule YAML, a Cloud Monitoring alert policy in Terraform, a Datadog monitor, each routed to TaskTrooper's alert ingest URL so it opens an incident here

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

makifbaysal/tasktrooper1172026년 10월 18일 업데이트

makifbaysal의 스킬 모두 보기

이 스킬의 문제 신고