testing · evanca — Claude Code skill for Flutter/Dart tests and setup
The testing skill guides Flutter and Dart test writing and review, helps investigate flaky tests, and clarifies when to use unit or widget tests.
MIT ★ 674 updated 2026-10-29
/plugin marketplace add evanca/flutter-ai-rules
/plugin install flutter-ai-skills@flutter-ai-rulesWhat testing does
The skill guides agents through tests for business logic, repositories, widgets, and cubits or blocs. It asks whether a test could catch a regression, rather than merely confirming that a mock returns what it was told to return. A mock-only check does not exercise real logic, so it can miss a broken implementation.
For unit tests, it covers test, bloc_test, and mocktail; for UI checks, it uses flutter_test and WidgetTester. It recommends wrapping widgets in MaterialApp, choosing pump() or pumpAndSettle() for the test’s needs, and using find.byKey when displayed text can vary. Test groups are organized around the class under test, with the test/ tree mirroring lib/.
The mocking guidance uses mocktail and calls for registerFallbackValue() when custom types go through any(). In Claude Code, install the skill from its marketplace or with npx skills.
What it helps with
- write unit tests for business logic or repositories
- check widget rendering and interactions
- spot tests that only confirm mock behavior
- investigate flaky tests
- choose between unit and widget tests
Example prompts for the agent
- Write unit tests for the business logic in this file and make sure they can catch regressions.
- Review the login screen’s widget test and check that it covers the error message.
- Investigate the flaky tests and decide which checks belong in unit tests versus widget tests.
How to install testing
1Plugin marketplace
/plugin marketplace add evanca/flutter-ai-rules/plugin install flutter-ai-skills@flutter-ai-rulesThis installs the whole flutter-ai-skills plugin with all its skills
2Skills CLI (Vercel)
npx skills add evanca/flutter-ai-rules --skill testing -a claude-code3Manually: put the files in place
~/.claude/skills/testing/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/testing/
1Skills CLI (Vercel)
npx skills add evanca/flutter-ai-rules --skill testing -a codex2Manually: put the files in place
.agents/skills/testing/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add evanca/flutter-ai-rules --skill testing -a cursor2Manually: put the files in place
.cursor/skills/testing/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install evanca/flutter-ai-rules skills/testing2Manually: put the files in place
.github/skills/testing/SKILL.md1Skills CLI (Vercel)
npx skills add evanca/flutter-ai-rules --skill testing -a gemini-cli2Platform CLI
gemini skills install https://github.com/evanca/flutter-ai-rules --path skills/testingManually: put the files in place
.devin/skills/testing/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about testing
How do I install testing in Claude Code?
Add the marketplace with /plugin marketplace add evanca/flutter-ai-rules, then install the skill with /plugin install flutter-ai-skills@flutter-ai-rules.
What does the testing skill do?
It guides Flutter and Dart test writing and review, helps choose test types, and gives advice on flaky tests, mocks, and file organization.
When should I use unit tests versus widget tests?
The skill recommends unit tests for business logic. Use widget tests to check rendering, gestures, or interactions with widgets.
Source text
SKILL.md · MIT
---
name: testing
description: "Use when writing or reviewing Flutter/Dart tests (unit, widget, golden), fixing flaky tests, adding coverage, or choosing between unit and widget tests."
license: MIT
---
# Testing Skill
Write effective, meaningful Flutter and Dart tests that catch real regressions.
## When to Use
Use this skill when:
* Writing unit tests for business logic, repositories, or utility classes.
* Writing widget tests for UI components.
* Reviewing existing tests for correctness and coverage.
* Fixing flaky or false-positive tests.
* Deciding between unit tests, widget tests, and integration tests.
---
## 1. Test Validity
Before writing or accepting a test, ask:
> **"Can this test actually fail if the real code is broken?"**
- Avoid tests that only confirm mocked/fake behavior without exercising real logic.
- Avoid tests that confirm behavior guaranteed by the language or standard library.
- Every test must be capable of catching a real regression.
```dart
// BAD — tests the mock, not real logic
test('should return user', () {
when(() => repo.getUser()).thenReturn(fakeUser);
expect(repo.getUser(), fakeUser); // Only proves the mock works
});
// GOOD — tests the cubit's state transitions driven by the mock
blocTest<UserCubit, UserState>(
'should emit loaded state when getUser succeeds',
build: () {
when(() => repo.getUser()).thenAnswer((_) async => fakeUser);
return UserCubit(repo);
},
act: (cubit) => cubit.fetchUser(),
expect: () => [
const UserState(status: UserStatus.loading),
UserState(status: UserStatus.loaded, user: fakeUser),
],
);
```
---
## 2. Structure
Always use `group()` in test files. Name the group after the **class under test**:
```dart
group('Counter', () {
late Counter counter;
setUp(() {
counter = Counter();
});
test('value should start at 0', () {
expect(counter.value, 0);
});
test('should increment value by 1', () {
counter.increment();
expect(counter.value, 1);
});
});
```
Rules:
- Use `setUp` for shared object creation; use `tearDown` for cleanup (closing streams, controllers).
- Keep each test focused on one behavior.
- Nest `group()` blocks for sub-features when a class has many methods.
---
## 3. Naming
Name test cases using **"should"** to describe expected behavior:
```dart
test('should emit updated list when item is added', () { ... });
test('should throw ArgumentError when input is negative', () { ... });
```
---
## 4. Unit Tests vs Widget Tests
| Type | Target | Tools |
|---|---|---|
| **Unit test** | Pure Dart logic, repositories, cubits/blocs | `test`, `bloc_test`, `mocktail` |
| **Widget test** | Individual widgets, UI behavior, navigation | `flutter_test`, `WidgetTester` |
Default to **unit tests** for business logic. Use **widget tests** when verifying UI rendering, gesture handling, or widget interaction.
---
## 5. Widget Test Patterns
```dart
testWidgets('should display error message on failure', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: BlocProvider<LoginCubit>.value(
value: mockLoginCubit,
child: const LoginView(),
),
),
);
// Simulate failure state
whenListen(
mockLoginCubit,
Stream.fromIterable([const LoginState(status: LoginStatus.failure, errorMessage: 'Invalid')]),
initialState: const LoginState(),
);
await tester.pump();
expect(find.text('Invalid'), findsOneWidget);
});
```
Rules:
- Wrap widgets in `MaterialApp` (or the app's root widget) to provide `MediaQuery`, `Directionality`, etc.
- Use `pump()` for a single frame or `pumpAndSettle()` when animations must complete.
- Prefer `find.byKey` over `find.text` for widgets that may have localized or dynamic text.
---
## 6. Mocking Best Practices
- Use `mocktail` for mocks (no code generation required).
- Call `registerFallbackValue()` in `setUpAll` for custom types passed to `any()`.
- Mock at the repository boundary, not at the HTTP/database layer.
```dart
class MockAuthRepository extends Mock implements AuthRepository {}
void main() {
setUpAll(() {
registerFallbackValue(FakeLoginRequest());
});
// ... tests
}
```
---
## 7. Test File Organization
```
test/
feature_a/
cubit/
feature_a_cubit_test.dart
view/
feature_a_view_test.dart
model/
feature_a_model_test.dart
```
- Mirror the `lib/` folder structure under `test/`.
- One test file per source file.
- Name test files `<source_file>_test.dart`.
© Ivanna Kaceviča · MIT · evanca/flutter-ai-rules
Similar skills
All skills for Testing and QA →testing by other authors comes first.