スキル一覧に戻る
abhishekbrt

flutter-testing

by abhishekbrt

glow state

0🍴 0📅 2026年1月11日
GitHubで見るManusで実行

SKILL.md


name: flutter-testing description: Flutter testing patterns with mocktail. Covers unit testing, widget testing, and BLoC/Cubit testing. Use when writing tests or setting up test infrastructure.

Flutter Testing

Test Commands

flutter test                                    # Run all tests
flutter test test/features/auth/               # Run feature tests
flutter test --plain-name "returns empty"      # Run by name pattern
flutter test --coverage                        # With coverage

Detailed Guides

TopicGuideUse When
Unit Testingunit-testing.mdTesting business logic, repositories, use cases
Widget Testingwidget-testing.mdTesting UI components, interactions
BLoC Testingbloc-testing.mdTesting BLoC/Cubit state management

Feature-First Test Structure

test/
├── features/
│   ├── auth/
│   │   ├── data/
│   │   │   ├── auth_repository_test.dart
│   │   │   └── auth_remote_source_test.dart
│   │   ├── domain/
│   │   │   └── login_usecase_test.dart
│   │   └── presentation/
│   │       ├── login_screen_test.dart
│   │       └── auth_bloc_test.dart
│   ├── home/
│   │   ├── data/
│   │   ├── domain/
│   │   └── presentation/
│   └── profile/
│       └── ...
├── core/
│   ├── network/
│   │   └── api_client_test.dart
│   └── utils/
│       └── validators_test.dart
└── helpers/
    ├── pump_app.dart          # Test wrapper with providers
    ├── mocks.dart             # Shared mock classes
    └── fixtures.dart          # Test data factories

Mocking with Mocktail

import 'package:mocktail/mocktail.dart';

class MockAuthRepository extends Mock implements AuthRepository {}

void main() {
  late MockAuthRepository mockRepo;

  setUp(() {
    mockRepo = MockAuthRepository();
  });

  test('returns user on successful login', () async {
    // Arrange
    when(() => mockRepo.login(any(), any()))
        .thenAnswer((_) async => User(id: '1', name: 'Test'));

    // Act
    final result = await mockRepo.login('email', 'pass');

    // Assert
    expect(result.name, equals('Test'));
    verify(() => mockRepo.login('email', 'pass')).called(1);
  });
}

Fakes vs Mocks

TypeUse WhenExample
MockVerify interactionsverify(() => mock.save(any())).called(1)
FakeNeed working implementationFakeAuthRepo with in-memory Map
StubFixed return valueswhen(() => mock.get()).thenReturn(value)

Dependencies

dev_dependencies:
  flutter_test:
    sdk: flutter
  mocktail: ^1.0.0
  bloc_test: ^9.1.0       # If using BLoC

Test Naming

// ✅ Describe behavior
test('returns empty list when no todos exist', () {});
test('throws AuthException when credentials invalid', () {});

// ❌ Don't describe implementation
test('test getTodos', () {});
test('login test', () {});

Arrange-Act-Assert

test('adds item to cart', () {
  // Arrange
  final cart = Cart();
  final item = Item(id: '1', price: 10.0);
  
  // Act
  cart.add(item);
  
  // Assert
  expect(cart.items, contains(item));
  expect(cart.total, equals(10.0));
});
group('LoginUseCase', () {
  group('when credentials valid', () {
    test('returns user', () {});
    test('caches auth token', () {});
  });

  group('when credentials invalid', () {
    test('throws AuthException', () {});
    test('does not cache token', () {});
  });
});

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です