测试理念
我们相信全面的测试是可靠性与可维护性的基础。测试套件包括:- Unit Tests:隔离测试单个组件
- Integration Tests:测试组件间交互
- End-to-End Tests:测试完整工作流
运行测试
测试结构
编写测试
Unit Test Example
Integration Test Example
最佳实践
Test Naming
Test Naming
- 使用描述性名称:
test_oauth_link_generates_valid_url - 以
test_开头 - 将相关测试按类分组
Fixtures
Fixtures
- 使用 fixtures 复用公共 setup
- fixtures 保持简单
- 谨慎使用
autouse=True
Mocking
Mocking
- Mock 外部服务
- 不要 mock 正在被测试的对象
- HTTP 调用建议使用
aioresponses
Assertions
Assertions
- 使用明确的 assertions
- 每个测试只验证一件事
- 添加有帮助的失败提示
持续集成(CI)
测试会通过 GitHub Actions 在每次 push 时自动运行。配置见.github/workflows/test.yml。