testing-flutter について
Flutter と Dart の開発者向けテストガイドです。BLoC や Riverpod を使うプロジェクトを対象に、BLoC v9 と Riverpod 3.0 のテストパターンを例とともに扱います。
主な機能
- 01BLoC v9 の bloc_test パターン
- 02Riverpod 3.0 Mutation のテスト
- 03テスト実践のガイドライン
活用シーン
- 01BLoC の状態とイベントのテスト
- 02Riverpod Mutation による状態更新の検証
- 03Flutter プロジェクトのテスト方針の策定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ thebeardedbearsas/ claude-craft --skill testing-flutterインストール後、Claude Code で/testing-flutterを入力して読み込まれたか確認します。
詳細
Flutter 3.44 以降のテスト — 完全ガイド
バージョン: Flutter 3.44 以降 | Dart 3.12 以降 | BLoC v9 | Riverpod 3.0
2026 年のテストパターン
bloc_test を使った BLoC v9 のテスト
// pubspec.yaml
dev_dependencies:
bloc_test: ^10.0.0
mocktail: ^1.0.0
// Test avec emit.isDone checks (BLoC v9)
blocTest<UserBloc, UserState>(
'emits [loading, loaded] when FetchUser is added',
build: () {
when(() => mockUseCase.call('123'))
.thenAnswer((_) async => User(id: '123', name: 'Alice'));
return UserBloc(getUserUseCase: mockUseCase);
},
act: (bloc) => bloc.add(const FetchUser('123')),
expect: () => [
const UserState(status: UserStatus.loading),
const UserState(status: UserStatus.loaded, user: User(id: '123', name: 'Alice')),
],
verify: (bloc) {
// Vérifier que le bloc respecte isDone (v9)
verify(() => mockUseCase.call('123')).called(1);
},
);
Riverpod 3.0 のミューテーションテスト
// Test Riverpod 3.0 Mutations API
test('Mutation updates state correctly', () async {
final container = ProviderContainer();
// Initial state
final notifier = container.read(orderNotifierProvider('123').notifier);
expect(container.read(orderNotifierProvider('123')).value?.id, '123');
// Mutation
await notifier.updateOrder(Order(id: '123', name: 'Updated'));
// Verify state après mutation
expect(
container.read(orderNotifierProvider('123')).value?.name,
'Updated',
);
container.dispose();
});
このスキルでは、ガイドラインとベストプラクティスを紹介します。
詳しい説明については、../../rules/07-testing-flutter.md を参照してください。
コメント
Markdown 対応