flutter-tester

Create isolated Flutter tests with Mockito, Riverpod, and GetIt.

57|67|Updated Nov 24, 2024
One-click install
npx skills add https://github.com/Namma-Flutter/namma_wallet --skill flutter-tester-namma-flutter
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: flutter-tester
Source: https://github.com/Namma-Flutter/namma_wallet/tree/main/.claude/flutter-tester
Command: npx skills add https://github.com/Namma-Flutter/namma_wallet --skill flutter-tester-namma-flutter

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Many Flutter projects suffer from fragile, slow, or non-deterministic tests due to improper mocking, missing lifecycle cleanup, unconfigured environment dependencies, and inconsistent widget test setup; this skill provides clear patterns and guardrails to make tests isolated, repeatable, and maintainable.

Core Features & Use Cases

  • Layered testing guidance: explicit patterns for repository, DAO, service, and provider tests so each layer is tested in isolation.
  • Riverpod & provider testing: how to override providers, use ProviderContainer helpers, and test AsyncNotifier lifecycles.
  • Widget and integration testing: screen sizing, key usage, platform overrides, navigation, and async handling with Completer and pump/pumpAndSettle.
  • Mocking and stubbing best practices: Mockito mock generation, when/then patterns, fake vs mock guidance, GetIt registration and reset, and SharedPreferences stubbing.
  • Error handling & cleanup: test error paths, verify logging, dispose resources, and ensure deterministic results across runs.

Quick Start

Create a unit test that verifies UserRepository.fetchUsers by mocking its DAO and API with Mockito, arranging success and error scenarios and asserting expected results.

Frequently Asked Questions about flutter-tester

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write reliable Flutter tests that don't break when dependencies change?

Reliable Flutter tests use proper mocking with Mockito, provider overrides for Riverpod, and GetIt registration resets to isolate each layer. This ensures tests remain repeatable and maintainable by enforcing test lifecycle cleanup and stubbing dependencies like SharedPreferences.

What's the best way to mock dependencies in a Flutter unit test?

Mocking dependencies in a Flutter unit test is best done using Mockito to generate mocks and define when/then behavior. You can stub DAO and API responses, arrange success and error scenarios, and verify expected results for isolated repository testing.

How do I test Riverpod providers and AsyncNotifier lifecycles in Flutter?

Testing Riverpod providers involves using ProviderContainer helpers to override providers and manage AsyncNotifier lifecycles. This approach isolates provider state, allowing you to assert async operations and ensure deterministic results across test runs.

Can I use Mockito and GetIt together for Flutter integration testing?

You can use Mockito and GetIt together for Flutter integration testing by registering mocks in GetIt and resetting them during the test lifecycle. This combination allows you to isolate service layers and stub dependencies for deterministic integration test scenarios.

How do I stub SharedPreferences in a Flutter unit test?

Stubbing SharedPreferences in a Flutter unit test requires creating a mock or fake instance using Mockito. You then define the expected return values for storage reads and writes, ensuring your service or repository tests remain isolated from actual device storage.