← ClaudeAtlas

flutter-test-widgetlisted

Widget testing using flutter_test
noory-code/noory-ai · ★ 0 · AI & Automation · score 74
Install: claude install-skill noory-code/noory-ai
# Flutter Widget Test Test a single widget's UI and interactions. --- ## Installation ```yaml # pubspec.yaml (included in the Flutter SDK) dev_dependencies: flutter_test: sdk: flutter ``` --- ## Quick Reference ### Basic Structure ```dart import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('MyWidget has title', (tester) async { // 1. build widget await tester.pumpWidget(const MyWidget(title: 'Hello')); // 2. find widget final titleFinder = find.text('Hello'); // 3. verify expect(titleFinder, findsOneWidget); }); } ``` ### Finders ```dart // find by text find.text('Hello') // find by type find.byType(ElevatedButton) // find by key find.byKey(const Key('submit_button')) // find by icon find.byIcon(Icons.add) // ancestor/descendant relationship find.descendant( of: find.byType(ListTile), matching: find.text('Item'), ) ``` ### Matchers ```dart expect(finder, findsOneWidget); // exactly 1 expect(finder, findsNothing); // 0 expect(finder, findsWidgets); // 1 or more expect(finder, findsNWidgets(3)); // exactly N expect(finder, findsAtLeast(2)); // at least N ``` ### Interactions ```dart // tap await tester.tap(find.byType(ElevatedButton)); await tester.pump(); // apply setState // enter text await tester.enterText(find.byType(TextField), 'hello'); await tester.pump(); // drag await tester.drag(find.byType(ListView), const Offset(0, -