vgv-testing
Dart & Flutter Testing
Testing fundamentals for Dart and Flutter projects — unit tests, widget tests, and golden file tests — using package:test, package:flutter_test, package:mocktail, and package:bloc_test.
Core Standards
Apply these standards to ALL test work:
- Descriptive test names — verbose, readable names that describe the behavior; never
'works'or'renders' - Hierarchical group/test structure that reads as natural sentences — top-level
groupfor the class, nestedgroupfor the method,testfor the behavior (e.g.,UserRepository→getUser→returns User when API succeeds) - String interpolation for type references — use
'returns $User'not'returns User'so renames propagate automatically - Private mocks per file — declare
class _MockX extends Mock implements X {}with underscore prefix to prevent cross-file coupling - Contained test setup within groups — all
setUp/tearDowncalls live inside agroup, never at the top level ofmain() - Initialize mutable objects in
setUp()withlate— declarelate MyDep dep;then assign insetUpso each test gets a fresh instance - No shared mutable state between tests — never use static members, global variables, or top-level final instances that persist across tests
- Use
package:mocktail— neverpackage:mockito - Constant test tags — use an
abstract class TestTagwithstatic constfields; never pass raw string literals as tags - Test behavior, not properties — widget tests focus on functional outcomes; static visual properties validated via golden tests
- Use
pumpApptest helper — wrap widgets via shared helper intest/helpers/pump_app.dart; never inlinepumpWidget(MaterialApp(...))
More from verygoodopensource/very_good_ai_flutter_plugin
vgv-static-security
>
26vgv-navigation
Best practices for navigation and routing in Flutter using GoRouter.
7vgv-accessibility
Flutter accessibility auditing and remediation with WCAG 2.1 level selection (A, AA, AAA) across mobile, desktop, and web platforms. Begins by asking the WCAG conformance level and target platform(s) before applying level-appropriate, platform-aware criteria.
7vgv-material-theming
Best practices for Flutter theming using Material 3.
7vgv-internationalization
Best practices for internationalization (i18n) and localization (l10n) in Flutter.
7vgv-bloc
Best practices for Bloc state management in Flutter/Dart. Use when writing, modifying, or reviewing code that uses package:bloc, package:flutter_bloc, or package:bloc_test.
5