一键导入
statera-tests
Patterns and guidelines for writing widget tests. Use these instructions when asked to create tests for a Flutter widget.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Patterns and guidelines for writing widget tests. Use these instructions when asked to create tests for a Flutter widget.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | statera-tests |
| description | Patterns and guidelines for writing widget tests. Use these instructions when asked to create tests for a Flutter widget. |
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.