$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
FlutterintermediateNew

Flutter Testing

Share

Write widget tests and integration tests for Flutter

Works with OpenClaude

You are a Flutter testing specialist. The user wants to write widget tests and integration tests for Flutter applications to verify UI behavior and user interactions.

What to check first

  • Run flutter test --help to confirm the Flutter testing framework is available
  • Verify pubspec.yaml includes flutter_test dependency under dev_dependencies
  • Check that test files exist in the test/ directory (widget tests) or integration_test/ directory (integration tests)

Steps

  1. Create a widget test file in test/ directory with _test.dart suffix (e.g., test/home_page_test.dart)
  2. Import flutter_test and the widget you want to test at the top of the file
  3. Wrap your test in a testWidgets() function which provides a WidgetTester instance
  4. Use WidgetTester.pumpWidget() to render your widget into the test environment
  5. Use finders like find.byType(), find.byKey(), or find.text() to locate widgets
  6. Use matchers like expect() to assert the widget state matches expected values
  7. Simulate user interactions with tester.tap(), tester.enterText(), or tester.drag()
  8. Call await tester.pumpAndSettle() to wait for animations and rebuilds to complete
  9. For integration tests, create files in integration_test/ and use testWidgets() with device-level interactions

Code

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('Counter Widget Tests', () {
    testWidgets('Counter increments when button is tapped', (WidgetTester tester) async {
      // Build the widget
      await tester.pumpWidget(
        const MaterialApp(
          home: CounterPage(),
        ),
      );

      // Verify initial state
      expect(find.text('0'), findsOneWidget);
      expect(find.byIcon(Icons.add), findsOneWidget);

      // Tap the increment button
      await tester.tap(find.byIcon(Icons.add));
      await tester.pump();

      // Verify counter incremented
      expect(find.text('1'), findsOneWidget);
      expect(find.text('0'), findsNothing);
    });

    testWidgets('Multiple taps increment correctly', (WidgetTester tester) async {
      await tester.pumpWidget(
        const MaterialApp(
          home: CounterPage(),
        ),
      );

      // Tap 5 times
      for (int i = 0; i < 5; i++) {
        await tester.tap(find.byIcon(Icons.add));
        await tester.pump();
      }

      expect(find.text('5'), findsOneWidget

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryFlutter
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
fluttertestingwidget-tests

Install command:

curl -o ~/.claude/skills/flutter-testing.md https://clskills.in/skills/flutter/flutter-testing.md

Related Flutter Skills

Other Claude Code skills in the same category — free to download.

Want a Flutter skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.