Agent skill

custom-plugin-flutter-skill-testing

1600+ lines of testing mastery - unit tests, widget tests, integration tests, E2E, coverage, mocking with production-ready code examples.

Stars 7
Forks 5

Install this agent skill to your Project

npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-flutter/tree/main/skills/testing

SKILL.md

custom-plugin-flutter: Testing & QA Skill

Quick Start - Complete Test Suite

dart
// Unit test
void main() {
  group('Calculator', () {
    late Calculator calc;

    setUp(() {
      calc = Calculator();
    });

    test('add returns sum', () {
      expect(calc.add(2, 3), equals(5));
    });
  });
}

// Widget test
void main() {
  testWidgets('Counter increments', (tester) async {
    await tester.pumpWidget(const MyApp());
    expect(find.text('0'), findsOneWidget);

    await tester.tap(find.byIcon(Icons.add));
    await tester.pump();

    expect(find.text('1'), findsOneWidget);
  });
}

// Integration test
void main() {
  group('User Flow', () {
    testWidgets('Complete user journey', (tester) async {
      await tester.pumpWidget(const MyApp());
      
      await tester.tap(find.text('Login'));
      await tester.pumpAndSettle();

      expect(find.text('Welcome'), findsOneWidget);
    });
  });
}

1. Unit Testing

dart
class UserService {
  Future<User> getUser(String id) async {
    // Implementation
  }
}

void main() {
  group('UserService', () {
    late UserService service;
    late MockUserRepository mockRepository;

    setUp(() {
      mockRepository = MockUserRepository();
      service = UserService(mockRepository);
    });

    test('getUser returns user', () async {
      final user = User(id: '1', name: 'John');
      when(mockRepository.getUser('1')).thenAnswer((_) async => user);

      final result = await service.getUser('1');

      expect(result, user);
      verify(mockRepository.getUser('1')).called(1);
    });

    test('getUser throws on error', () async {
      when(mockRepository.getUser('1'))
          .thenThrow(Exception('Not found'));

      expect(
        () => service.getUser('1'),
        throwsException,
      );
    });
  });
}

2. Widget Testing

dart
void main() {
  testWidgets('Render user card', (tester) async {
    const user = User(id: '1', name: 'John Doe', email: 'john@example.com');

    await tester.pumpWidget(
      MaterialApp(home: Scaffold(body: UserCard(user: user))),
    );

    expect(find.text('John Doe'), findsOneWidget);
    expect(find.text('john@example.com'), findsOneWidget);
  });

  testWidgets('Tap user card navigates', (tester) async {
    const user = User(id: '1', name: 'John Doe', email: 'john@example.com');

    await tester.pumpWidget(MaterialApp(home: Scaffold(body: UserCard(user: user))));

    await tester.tap(find.byType(UserCard));
    await tester.pumpAndSettle();

    expect(find.byType(UserDetailPage), findsOneWidget);
  });
}

3. Mocking

dart
class MockUserRepository extends Mock implements UserRepository {}

final mockRepository = MockUserRepository();

// Setup mock behavior
when(mockRepository.getUser('1')).thenAnswer((_) async => User(...));

// Verify calls
verify(mockRepository.getUser('1')).called(1);

// Capture arguments
final captured = verify(mockRepository.updateUser(captureAny)).captured;

4. Integration Testing

dart
void main() {
  group('User Creation Flow', () {
    testWidgets('Create user and verify', (tester) async {
      await tester.pumpWidget(const MyApp());

      // Navigate to create user
      await tester.tap(find.text('Add User'));
      await tester.pumpAndSettle();

      // Fill form
      await tester.enterText(find.byKey(Key('nameField')), 'John');
      await tester.enterText(find.byKey(Key('emailField')), 'john@example.com');

      // Submit
      await tester.tap(find.text('Create'));
      await tester.pumpAndSettle();

      // Verify result
      expect(find.text('User created'), findsOneWidget);
    });
  });
}

Ensure bulletproof quality with comprehensive testing.

Expand your agent's capabilities with these related and highly-rated skills.

pluginagentmarketplace/custom-plugin-flutter

custom-plugin-flutter-skill-animations

Production-grade Flutter animations mastery - Implicit and explicit animations, AnimationController, Hero transitions, physics-based motion, Lottie/Rive integration, 60fps optimization with comprehensive code examples

7 5
Explore
pluginagentmarketplace/custom-plugin-flutter

custom-plugin-flutter-skill-navigation

Production-grade Flutter navigation mastery - Navigator 2.0, GoRouter, deep linking, nested navigation, route guards, web URL handling with comprehensive code examples

7 5
Explore
pluginagentmarketplace/custom-plugin-flutter

custom-plugin-flutter-skill-localization

Production-grade Flutter localization mastery - ARB files, flutter_localizations, intl package, pluralization, RTL support, dynamic locale switching with comprehensive code examples

7 5
Explore
pluginagentmarketplace/custom-plugin-flutter

custom-plugin-flutter-skill-accessibility

Production-grade Flutter accessibility mastery - Semantics API, screen readers (VoiceOver/TalkBack), WCAG 2.1 AA/AAA compliance, inclusive design patterns, automated a11y testing with comprehensive code examples

7 5
Explore
pluginagentmarketplace/custom-plugin-flutter

custom-plugin-flutter-skill-state

2300+ lines of state management mastery - all patterns (Provider, Riverpod, BLoC, GetX), dependency injection, persistence, testing with production-ready code examples.

7 5
Explore
pluginagentmarketplace/custom-plugin-flutter

custom-plugin-flutter-skill-database

1800+ lines of database architecture mastery - SQLite, Hive, ObjectBox, Firestore, encryption, offline-first, sync with production-ready code examples.

7 5
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results