testing-strategies
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOverview
概述
This skill provides strategies for test design, test coverage, test organization, and testing best practices across different testing types and frameworks.
本Skill提供适用于不同测试类型和框架的测试设计、测试覆盖率、测试组织以及测试最佳实践策略。
Test Coverage Targets
测试覆盖率目标
- Critical Code (auth, payment, security): 100%
- Business Logic: 90-100%
- Utilities: 80-90%
- UI Components: 70-80%
- Overall Project: 80%+
- 关键代码(认证、支付、安全):100%
- 业务逻辑:90-100%
- 工具类:80-90%
- UI组件:70-80%
- 整体项目:80%+
Test Types
测试类型
Unit Tests
单元测试
- Test individual functions/methods in isolation
- Use mocks for dependencies
- Fast execution (<1ms per test)
- Cover happy path, edge cases, errors
- 独立测试单个函数/方法
- 对依赖项使用mock
- 执行速度快(每个测试<1毫秒)
- 覆盖正常流程、边界情况、错误场景
Integration Tests
集成测试
- Test component interactions
- Use real dependencies where reasonable
- Test API endpoints, database operations
- Moderate execution time
- 测试组件间的交互
- 合理情况下使用真实依赖项
- 测试API接口、数据库操作
- 执行时间适中
End-to-End Tests
端到端测试
- Test complete user workflows
- Use real system components
- Critical paths only (slower execution)
- 测试完整用户工作流
- 使用真实系统组件
- 仅覆盖关键路径(执行速度较慢)
Test Case Pattern
测试用例模式
For each function, create tests for:
- Happy Path: Normal, expected inputs
- Edge Cases: Boundary values, empty inputs
- Error Cases: Invalid inputs, exceptions
- Special Cases: Nulls, zeros, large values
针对每个函数,创建以下测试:
- 正常流程:符合预期的常规输入
- 边界情况:边界值、空输入
- 错误场景:无效输入、异常情况
- 特殊场景:空值、零、大数值
Test Organization
测试组织
tests/
├── unit/
│ ├── test_module1.py
│ └── test_module2.py
├── integration/
│ └── test_api.py
└── e2e/
└── test_workflows.pytests/
├── unit/
│ ├── test_module1.py
│ └── test_module2.py
├── integration/
│ └── test_api.py
└── e2e/
└── test_workflows.pyWhen to Apply
适用场景
Use when creating test suites, improving coverage, fixing failing tests, or designing test strategies.
适用于创建测试套件、提升覆盖率、修复失败测试或设计测试策略时。