-
use customPump() from test/helpers.dart to pump a widget under test.
-
pass any providers (including Cubits/Blocs) via extraProviders.
-
stub/mock only the required dependencies of the widget under test. The test should fail if any mock is removed.
-
for BlocListener-driven widgets, stub state and/or stream depending on what is being used in the widget:
when(cubit.state).thenReturn(SomeState());
when(cubit.stream).thenAnswer((_) => Stream.value(SomeState()));
-
mocks are generated by Mockito — each service class has @GenerateNiceMocks([MockSpec<T>()]) on it and a corresponding .mocks.dart file. After adding a new mock annotation, regenerate with dart run build_runner build.
-
BLoC-unit tests use the bloc_test package (blocTest<>, seed:, act:, expect:).
-
always extract a helper method that pumps the widget under test, it should be named pump[WidgetName].
-
place helper methods AFTER all the tests in the test file.