CI enforces at least 50% line coverage (min_coverage: 50 in
.github/workflows/main.yaml). This is intentionally below VGV's usual 100%.
Prioritize:
- Repositories and data clients — pure Dart, cheap to test, high value.
- Blocs/Cubits — every event handler and resulting state.
- Widgets with logic (conditional rendering, dispatching events).
Trivial layout widgets and generated code may go untested.
- Tests mirror the source tree:
lib/inspector/bloc/inspector_bloc.dart→test/inspector/bloc/inspector_bloc_test.dart. - Packages have their own
test/folder and run independently. - Shared helpers live in
test/helpers/(import../helpers/helpers.dart). Usetester.pumpApp(widget)so widgets get the same providers/theme as in the app; extendpumpAppas new providers are added.
bloc_test—blocTest<MyBloc, MyState>(...)for blocs/cubits.mocktail— mocks for repositories (class _MockComponentRepository extends Mock implements ComponentRepository {}) and blocs (MockBloc/MockCubitfrombloc_test).
- Group by the unit under test:
group(MyBloc, () { ... }). - Test descriptions read as sentences:
'emits [loading, success] when ...'. - Each test sets up its own state; tests run in random order
(
--test-randomize-ordering-seed random), so no shared mutable state. - Mock the layer directly beneath the unit under test — never deeper.
flutter test --coverage --test-randomize-ordering-seed random
# optional: view report (requires lcov)
genhtml coverage/lcov.info -o coverage/ && open coverage/index.html