flutter-testing-standards
Unit, widget, and integration testing using mocktail and bloc_test.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Testing Standards
Priority: P1 (HIGH)
Ensuring code reliability through multi-layered testing strategies.
Structure
test/
├── unit/ # Business logic & mapping (Blocs, Repositories, UseCases)
├── widget/ # UI component behavior (Screens, Widgets)
└── integration/ # End-to-end flows
Implementation Guidelines
- Testing Pyramid: Maintain ~70% Unit Tests, ~20% Widget Tests, ~10% Integration Tests.
-
Mocks: Use
mocktailfor type-safe, boilerplate-free mocking. - Unit Tests: Test logic in isolation. Verify all edge cases (Success, Failure, Exception).
- Widget Tests: Test high-value interactions (Button clicks, Error states, Loading indicators).
-
BLoC Tests: Use
blocTestto verify state emission sequences. - Code Coverage: Aim for 80%+ coverage on Domain and Presentation (Logic) layers.
Deep Dive References
- Unit Testing Strategies (Test Data Builders, Mocktail)
- Widget Testing Strategies (Robot Pattern)
- Integration Testing (Shared Robots, Real Device)
- Robot Pattern Implementation
🚫 Anti-Patterns
-
Thread Sleep:
**No Future.delayed**: Use FakeAsync or expectations for deterministic timing. -
Missing Assertions:
**No "Execution Only" Tests**: A test without an expect() call is invalid. -
Over-Mocking:
**No Mocking Data Classes**: Use real instances for Entities/Models; mock only I/O. -
Test Pollution:
**No Shared State**: Ensure every test is Independent (FIRST).
Related Topics
layer-based-clean-architecture | dependency-injection | cicd
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!