Use when writing acceptance criteria for a task - express each as an observable Given/When/Then that QA can execute, including negative cases
中文简介正在准备中。当前显示原文说明。
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
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
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.
| Layer | Question | Tool |
|---|---|---|
| Unit | Does the controller/logic compute correctly? | flutter_test, mock the repository |
| Widget | Does the widget render state and respond to taps? | testWidgets + pumpWidget + finders |
| Golden | Does it match the approved pixels? | matchesGoldenFile |
| Integration | Does the whole flow work on a device? | integration_test |
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
});
mocktail per the app's convention.pump vs pumpAndSettle: use pump for controlled frames, pumpAndSettle to drain animations — never rely on real timers.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.
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.
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.@Tags(['golden'])) and generate/update them on one OS consistently (match CI's).--update-goldens to make a red test green without looking at the diff first — that silently accepts a visual regression as the new baseline.pumpWidget for logic that could be a plain unit test (slow, indirect).还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Use when writing acceptance criteria for a task - express each as an observable Given/When/Then that QA can execute, including negative cases
中文简介正在准备中。当前显示原文说明。
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
中文简介正在准备中。当前显示原文说明。
Use on every UI change - semantic HTML, labels for controls, keyboard-navigable dialogs/menus, visible focus, and never color as the only signal
中文简介正在准备中。当前显示原文说明。
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
中文简介正在准备中。当前显示原文说明。
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.
中文简介正在准备中。当前显示原文说明。
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
中文简介正在准备中。当前显示原文说明。