agentsclimarketplace

Flutter tdd

Skill UnleashedServices/vault-plugin/skills/flutter-tdd

Test-driven development patterns for Vault — red-green-refactor, mocktail, Riverpod testing, Drift in-memory DB, widget testsFrom its SKILL.md

Install
npx -y skills add UnleashedServices/vault-plugin --skill flutter-tdd

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

3.0 KB, as published. Nobody here has run it

Flutter TDD Patterns

Core Principles

  • Red-Green-Refactor: write failing test first, then make it pass, then clean up
  • mocktail for mocking — no code generation needed
  • ProviderContainer with overrides for Riverpod unit tests
  • ProviderScope with overrides for widget tests
  • In-memory NativeDatabase() for Drift integration tests
  • Test naming: test('should [behavior] when [condition]', ...)

Unit Test Pattern

import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockPasswordRepository extends Mock implements PasswordRepository {}

void main() {
  late MockPasswordRepository mockRepo;
  late ProviderContainer container;

  setUp(() {
    mockRepo = MockPasswordRepository();
    container = ProviderContainer(
      overrides: [passwordRepositoryProvider.overrideWithValue(mockRepo)],
    );
  });

  tearDown(() => container.dispose());

  group('PasswordListNotifier', () {
    test('should load passwords for vault on build', () async {
      when(() => mockRepo.getPasswords('v1'))
          .thenAnswer((_) async => [testPassword]);

      final result = await container
          .read(passwordListNotifierProvider('v1').future);

      expect(result, hasLength(1));
      expect(result.first.title, 'GitHub');
    });

    test('should handle error gracefully', () async {
      when(() => mockRepo.getPasswords('v1'))
          .thenThrow(const DatabaseFailure('connection lost'));

      final result = container.read(passwordListNotifierProvider('v1'));

      expect(result, isA<AsyncError>());
    });
  });
}

Widget Test Pattern

testWidgets('should show empty state when no passwords', (tester) async {
  await tester.pumpWidget(
    ProviderScope(
      overrides: [
        passwordStreamProvider('v1')
            .overrideWith((ref) => Stream.value(<Password>[])),
      ],
      child: const MaterialApp(home: PasswordsScreen()),
    ),
  );

  await tester.pumpAndSettle();
  expect(find.text('No passwords yet'), findsOneWidget);
  expect(find.byType(FloatingActionButton), findsOneWidget);
});

Drift Database Test Pattern

void main() {
  late AppDatabase db;

  setUp(() => db = AppDatabase(NativeDatabase.memory()));
  tearDown(() => db.close());

  test('should insert and query password', () async {
    await db.passwordDao.insert(PasswordsCompanion.insert(
      vaultId: 'vault-1',
      title: 'GitHub',
      username: '[email protected]',
      encryptedPassword: 'enc-data',
    ));

    final results = await db.passwordDao.watchByVault('vault-1').first;
    expect(results, hasLength(1));
    expect(results.first.title, 'GitHub');
  });
}

Coverage Requirements

  • New features: tests for all repository methods and notifier actions
  • Bug fixes: regression test reproducing the bug before the fix
  • UI: widget tests for loading, data, error, and empty states

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.