generate-tests
Generate unit and UI tests for specified code with edge cases and mocks
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Generate Tests
Generate unit and UI tests for specified code with edge cases and mocks.
Input Required
Specify what to test:
- File path or function/type name
- Type of tests needed: Unit / Integration / UI
- Any specific scenarios to cover
Test Generation Process
Step 1: Analyze Target Code
-
Read the code to understand:
- Public API surface
- Dependencies (what needs mocking)
- Side effects (network, persistence, notifications)
- Edge cases and error conditions
-
Identify testable behaviors:
- Happy path scenarios
- Error/failure scenarios
- Boundary conditions
- State transitions
Step 2: Test Plan
| Scenario | Input | Expected Output | Type |
|---|---|---|---|
| Unit/Integration/UI |
Step 3: Dependencies & Mocks
Dependencies to mock:
| Dependency | Mock Strategy |
|---|---|
| Network service | Protocol + mock implementation |
| Database | In-memory container |
| UserDefaults | Dedicated test suite |
| Date/Time | Inject fixed dates |
Step 4: Generate Tests
Use Swift Testing framework (import Testing) for new tests:
import Testing
@testable import Stuffolio
struct [Target]Tests {
@Test func [scenario]_[condition]_[expectedResult]() async throws {
// Given
// When
// Then
}
}
Step 5: Test Naming Convention
Follow: [method]_[scenario]_[expectedBehavior]
Examples:
-
fetchItems_whenNetworkAvailable_returnsItems -
saveItem_withEmptyTitle_throwsValidationError
Step 6: Coverage Checklist
- All public methods
- All code branches (if/else, switch cases)
- Error throwing paths
- Boundary values (empty, nil, max, min)
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-03-11
- 索引更新时间
- 2026-03-11
- 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!