Skip to content
Skills Library
Programming · Testing

flutter-testing

/flutter-testing

Use when defining automated testing strategies, organizing test pyramids, or establishing test naming conventions across Flutter apps.

Repository
skills ↗
Licence
MIT
Last repository change
30.08.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 30.08.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use when defining automated testing strategies, organizing test pyramids, or establishing test naming conventions across Flutter apps.

Original author description

Use when defining automated testing strategies, organizing test pyramids, or establishing test naming conventions across Flutter apps.

How it works

  1. Golden Variant Testing
  2. State Matrix Testing
  3. Interaction Contract Testing
Original SKILL.md headings · 69 lines, 585 words
SKILL.md preview
---
name: flutter-testing
description: Use when defining automated testing strategies, organizing test pyramids, or establishing test naming conventions across Flutter apps.
metadata:
    platforms: "flutter"
    languages: "dart"
    category: "testing"
---

# Testing Strategy

-   **Test Pyramid**: More unit and widget tests, fewer integration tests. Unit tests are fastest and cheapest.
-   **Mirror Test Rule**: 100% logic and widget coverage. No code without a test.
-   **Mirror Organization**: Test files MUST strictly mirror the `lib/` directory structure and end with `_test.dart`.
-   **Coverage Targets**: Target 100% logic coverage for `domain` and `bloc` layers.
-   **Test Independence**: Each test MUST be independent. No shared mutable state between tests.

# Test Types Overview

| Type | Scope | Speed | Skill |
|---|---|---|---|
| **Unit** | Single function/class | Fast | `dart-testing` |
| **Widget** | Single UI component | Medium | `flutter-add-widget-test` |
| **Integration** | Full app / user flow | Slow | `flutter-add-integration-test` |

# Pattern-Based Testing

These three patterns cut repetitive test setup, cover all visual states, and keep widget behavior consistent. They're conventions, not packages.

## Golden Variant Testing
When a widget has multiple visual states (primary, disabled, hover, error), test all variants in a single structured `group()` with a `Map<String, Widget Function()>`:
-   Define a `variants` map where keys are state names and values are widget builders.
-   Each variant MUST be rendered in isolation (fresh `pumpWidget` call per variant).
-   Use deterministic golden file naming: `goldens/<component>.<variant>.png`.
-   Set a consistent `surfaceSize` via `tester.view.physicalSize` to avoid flaky pixel diffs.
-   **When to use**: Design system components, widgets with distinct modes/types.
-   **When NOT to use**: Integration tests or animation frame verification.

## State Matrix Testing
Every stateful widget MUST be tested against ALL possible UI states. Use a state matrix to separate setup from verification:
-   Define a `states` map with every state the widget can render (`loading`, `error`, `data`, `empty`).
-   Write a single `verify(stateName)` callback that asserts correct rendering per state using `switch` expressions.
-   This pattern prevents the common mistake of only testing the "happy path".
-   **When to use**: Widgets with complex state machines (e.g., BLoC-driven screens).
-   **When NOT to use**: If verification logic varies wildly between states, write separate tests.

## Interaction Contract Testing
Reusable widgets have implicit behavioral rules. Define these as explicit, reusable contracts:
-   Create helper functions in `test/utils/` for common contracts:
    -   `verifyTappable(tester, finder, mockCallback)`: Tap fires callback exactly once.
    -   `verifyDisabledNotTappable(tester, finder, mockCallback)`: Tap does NOT fire callback when disabled.
    -   `verifyValidatesOnBlur(tester, finder)`: Validation triggers when focus leaves.
-   Apply contracts consistently across all widgets sharing the same behavior.
-   **When to use**: Widgets with strictly defined behavioral rules that must hold across refactors.
-   **When NOT to use**: One-off logic unique to a single widget.

# Test Naming & Structure

-   **Test Naming**: Use string interpolation for test group names: `group('$ClassName',` not `group('ClassName',`. This ensures consistency and enables better tooling support.
-   **Test Grouping**: Use `group()` to organize tests by feature, class, or state for clearer reporting.
-   **Descriptive Names**: Test names should clearly describe what is being tested and why.

# Common Test Errors

-   `A RenderFlex overflowed...`: Wrap widget in `Expanded` or constrain dimensions in test
-   `Vertical viewport was given unbounded height`: Wrap `ListView` in `SizedBox` with fixed height in test
-   `setState called during build`: Defer state changes to post-frame callback
-   `No MediaQuery widget ancestor`: Always wrap test widget in `MaterialApp`

# Running Tests (Quick Reference)

-   `flutter test`: Run all unit and widget tests
-   `flutter test test/path/to/file_test.dart`: Run specific test file
-   `flutter test integration_test/`: Run integration tests
-   `flutter test --coverage`: Run with coverage report
-   `dart test`: Pure Dart unit tests

Versions

RepositoryScoreLicence
This page · dhruvanbhalara/skills90MIT
HoangNguyen0403/agent-skills-standard100MIT
moustafadev/flutter-ai-skills100MIT
Dee9975/cc-skills-flutter100MIT
Albaylar/Mobile-Development-Kit100MIT
testland/qa100MIT
abdukabirov/flutter-agent-skills100MIT
thiennc-tesoglobal/flutter-skills100BSD-3-Clause
ethiel97/flutter-clean-riverpod-skills100MIT

Database snapshot: 13.11.2026 · package version 1ea1c414a931 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 95testing-flutter
    Testing Flutter 3.47 / BLoC v9 / Riverpod 3 - Stratégie Complète. Use when writing tests, reviewing test coverage, or setting up testing.
  • 95qa-strategy
    Testing strategy and QA patterns. Use for test pyramid design, E2E test architecture, test automation frameworks, performance testing, and bug triage processes.
  • 100flutter-testing-apps
    Implements unit, widget, and integration tests for a Flutter app. Use when ensuring code quality and preventing regressions through automated testing.
  • 80alpha-core:testing-patterns
    Provides testing strategies including test pyramid, TDD/BDD, unit/integration/E2E patterns, mocking strategies, test data factories, snapshot testing, and mutation testing. Use when designing test strategies, writing tests, or improving test coverage.
  • 85flutter-core:flutter-testing-quality
    Comprehensive Flutter testing and quality assurance guidance covering unit testing, widget testing, integration testing, golden tests, debugging techniques, code coverage, test-driven development, mocking strategies, DevTools profiling, and quality metrics. Use when testing…
  • 100eng-testing
    Use when writing tests, designing test strategy, or reviewing test coverage. Covers test pyramid, naming, mocking, and flaky test policy.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.