1. Objective
Generate structured test cases based on test points, covering positive, negative, and boundary scenarios.
2. Input and Output
- Input:
test-case/plan.md、clarified-requirements/index.md、CLAUDE.md - Output:
test-case/{ITEM}/{POINT}.md、test-case/all_cases.md
3. Core Principles
- Strategy Guidance: Provide judgment criteria, not a mandatory quantity
- Scenario-Driven: Generate test cases based on actual scenario complexity
- Specific Data: Test data must be specific, do not use placeholders
- Verifiability: Expected results must be clear and verifiable
Trigger Conditions
- User executes the
/testcase-gencommand test-case/plan.mdexists
4. Core Theories
4.1 Equivalence Class Partitioning
Divide input data into several equivalence classes, and select representative data from each class for testing.
Application Example:
POINT: 用户名密码登录
输入项: 用户名、密码
用户名等价类:
有效: [6-20字符,字母数字下划线] → "test_user123"
无效: [<6] "ab" | [>20] "verylongusername12345" | [特殊字符] "user@name" | [空] ""
密码等价类:
有效: [8-20字符,含大小写+数字] → "Test1234"
无效: [<8] "Test12" | [缺大写] "test1234" | [空] ""
生成原则: 一次测试一个等价类,其他保持有效
4.2 Boundary Value Analysis
Boundaries are the most error-prone places.
Boundary Three-Point Method: off point (min-1) | on point (min) | inner point (middle value) | on point (max) | off point (max+1)
Application Example:
用户名长度 6-20 字符:
- 离点-下: 5字符 "abcde" → 失败
- 上点-下: 6字符 "abcdef" → 成功
- 内点: 13字符 "test_user_123" → 成功
- 上点-上: 20字符 "test_user_1234567890" → 成功
- 离点-上: 21字符 "test_user_12345678901" → 失败
4.3 Judgment of Number of Test Cases
There is no mandatory quantity; adjust adaptively according to scenario complexity.
Judgment Criteria:
- Number of input items: the more input items, the more test cases
- Business rule complexity: the more complex the rules, the more test cases
- Risk level: Critical and High require more test cases
- Test concerns: the more concerns, the more test cases
5. Test Case Format Specification
5.1 Markdown Text Protocol Format (v0.2)
Generate one .md file for each test point, with the following format:
## [P1] 用例标题
[测试类型] 功能
[前置条件] 前置条件描述
[测试步骤] 1. 步骤1。2. 步骤2
[预期结果] 1. 预期1。2. 预期2
## [P3][反向] 用例标题
[测试类型] 功能
[前置条件] 前置条件描述
[测试步骤] 1. 步骤1。2. 步骤2
[预期结果] 1. 预期1。2. 预期2
5.2 Field Description
- Priority: P1-P5 (required)
- P1: Core function positive flow
- P2: Basic function positive flow
- P3: Core function exception scenarios
- P4: Boundary conditions
- P5: Low-frequency scenarios
- [Negative]: Negative test case marker (optional)
- Test Type: Function, Interface, Performance, Security, Compatibility, Usability, Installation and Deployment, Reliability, Localization, Maintainability, Scalability, Configuration (choose 1 of 12)
- Preconditions: Preparation work before testing
- Test Steps: Operation steps, separated by periods
- Expected Results: Expected results, corresponding one-to-one with the steps
5.3 Test Type Enumeration (12 types)
功能
兼容性
易用性
性能
稳定性
安全性
可靠性
效果(AI类、资源类)
效果(硬件器件类)
可维护性
可移植性
埋点
Note:
- Do not write "functional testing"; it must be "Function"
- Parentheses must be Chinese parentheses
- Case-sensitive
5.4 Step Format Specification
Recommended Format: Use Chinese periods as separators, with continuous numbering
[测试步骤] 1. 打开登录页面。2. 输入用户名test_user。3. 输入密码Test1234。4. 点击登录按钮
[预期结果] 1. 页面正常显示。2. 用户名输入框显示内容。3. 密码输入框显示密码。4. 登录成功,跳转到首页
Important: Numbering must start from 1 and increase continuously; the number of test steps and expected results must be consistent.
5.5 Test Data Requirements
Must be specific, do not use placeholders:
Correct example:
- Username: test_user
- Password: Test1234
- Phone number: 13800138000
- Amount: 99.99
Incorrect example:
- Username: {valid_username}
- Password: {password}
- Phone number: {phone}
- Amount: {amount}
5.6 Expected Result Requirements
Must be clearly verifiable:
Correct example:
- Jump to the /home page, with "Welcome, test_user" displayed at the top
- Prompt "Password length is insufficient, please enter a password of 8-20 characters"
- The order status changes to "Paid", and inventory decreases by 1
Incorrect example:
- Login successful
- Prompt an error message
- The system processes normally
5.7 Directory Structure
test-case/
├── plan.md
├── {ITEM}/
│ ├── {POINT1}.md
│ ├── {POINT2}.md
│ └── ...
└── all_cases.md
5.8 Merge Rules
Merge all {ITEM}/{POINT}.md into all_cases.md:
- Group by ITEM
- Sort by POINT under each ITEM
- Add separator markers:
# ITEM 名称and## POINT 名称
6. Test Case Generation Process
Step 1: Prepare context
cat test-case/plan.md
cat clarified-requirements/index.md
cat CLAUDE.md
Step 2: Understand test points
For each POINT:
- Read the POINT name, risk level, and test focus
- Read the relevant descriptions in the requirements document
Step 3: Identify input items
- List all input items (fields, parameters, operations, etc.)
- Identify the constraints of the input items
Step 4: Divide equivalence classes and boundary values
- Valid equivalence class: input that conforms to the rules
- Invalid equivalence class: input that violates the rules
- Boundary values: critical points (minimum value, maximum value, critical value)
Step 5: Design test cases
Design based on the following strategy:
Core thinking framework:
-
Input analysis
- Which input items does this scenario involve?
- What constraints does each input have (length, format, range)?
-
Equivalence class identification
- Valid equivalence class: typical values under normal conditions
- Invalid equivalence class: various abnormal situations (empty values, out of range, format errors)
-
Test value evaluation
- If this equivalence class fails, will it expose different defects?
- If the test logic is the same as other equivalence classes, can it be merged?
- How can the scenarios mentioned in the test focus be reflected in the test cases?
-
Coverage judgment
- There is at least one test case for the valid flow
- Core exception scenarios are covered
- Boundary conditions are selected according to the actual situation
-
Test case design
- Core positive test case (P1): the most common success scenario
- Basic positive test case (P2): other valid equivalence classes
- Core exception test case (P3): key failure scenarios
- Boundary condition test case (P4): boundary value testing
- Low-frequency scenario test case (P5): uncommon but must-cover scenarios
Test case quality standards:
- Specific data ("test123", not "correct username")
- Expected result is verifiable ("displays error message 'Username cannot be empty'", not "shows error")
- Naming convention (starts with "Verify")
Step 6: Unified validation after generation is complete
- After each test item (ITEM) is generated, call the validation script to check the format
- After all test items are generated, call the validation script again for an overall check
- Validation script path:
.claude/skills/testcase-generator/scripts/validate.py
7. Examples
Example 1: Correct test cases (username and password login)
## [P1] 验证有效用户名和密码登录成功
[测试类型] 功能
[前置条件] 已注册用户test_user,密码Test1234
[测试步骤] 1. 输入用户名test_user,输入密码Test1234,点击登录。2. 验证跳转到首页并显示用户名
[预期结果] 1. 登录请求成功。2. 跳转到/home页面,顶部显示'欢迎,test_user'
## [P3][反向] 验证用户名为空时登录失败
[测试类型] 功能
[前置条件] 进入登录页
[测试步骤] 1. 不输入用户名,输入密码Test1234,点击登录。2. 验证提示'用户名不能为空'
[预期结果] 1. 登录请求被拒绝。2. 停留在登录页,用户名输入框下方显示红色提示'用户名不能为空'
## [P4] 验证密码长度边界值(8位)
[测试类型] 功能
[前置条件] 已注册用户test_user,密码Test1234
[测试步骤] 1. 输入用户名test_user,输入8位密码Test1234,点击登录。2. 验证登录成功
[预期结果] 1. 登录请求成功。2. 跳转到/home页面
Example 2: Comprehensive scenario (multiple input items)
POINT: Ad account list - filter function
Input item analysis:
- Time range: [Today|Yesterday|Last 7 days|Custom]
- Account name: [text fuzzy search]
- Account status: [Normal|Banned|Under review]
Generate test cases (6):
## [P1] 验证单一条件筛选成功
[测试类型] 功能
[前置条件] 广告账户列表页面,有10个账户
[测试步骤] 1. 选择时间"近7天",点击查询。2. 验证返回符合条件的账户
[预期结果] 1. 列表刷新。2. 仅显示近7天有数据的账户
## [P1] 验证多条件组合筛选成功
[测试类型] 功能
[前置条件] 同上
[测试步骤] 1. 选择时间"近7天",输入名称"test",选择状态"正常",点击查询
[预期结果] 1. 列表刷新。2. 仅显示同时满足3个条件的账户
## [P3][反向] 验证时间超过365天筛选失败
[测试类型] 功能
[前置条件] 同上
[测试步骤] 1. 选择自定义时间,开始日期2023-01-01,结束日期2024-01-02,点击查询
[预期结果] 1. 显示提示"时间范围不能超过365天",列表不刷新
## [P3][反向] 验证不存在的账户名筛选返回空
[测试类型] 功能
[前置条件] 同上
[测试步骤] 1. 输入不存在的账户名"nonexistent123",点击查询
[预期结果] 1. 列表刷新。2. 显示"暂无数据"
## [P2] 验证筛选条件清空功能
[测试类型] 功能
[前置条件] 已应用筛选条件
[测试步骤] 1. 点击"重置"按钮。2. 验证所有筛选条件清空,列表恢复默认
[预期结果] 1. 所有筛选项恢复默认值。2. 列表显示全部账户
## [P4][反向] 验证结束时间早于开始时间提示错误
[测试类型] 功能
[前置条件] 同上
[测试步骤] 1. 选择自定义时间,开始日期2024-01-02,结束日期2024-01-01,点击查询
[预期结果] 1. 显示提示"结束时间不能早于开始时间"
Description:
- Medium-complexity POINT (multiple input items) generates 6 test cases
- Coverage: valid combinations, invalid boundaries, clear operations
- Selectrepresentative test cases, covering the main scenarios
Example 3: Incorrect test cases
## [P1] 验证登录成功
[测试类型] 功能
[前置条件] 用户已注册
[测试步骤] 1. 输入用户名{username},输入密码{password},点击登录
[预期结果] 1. 登录成功
Why it is incorrect:
- Test data uses placeholders ({username}, {password})
- Expected result is not verifiable ("Login successful" is too vague)
8. Validation process
Step 1: After each test item is generated
Call the validation script to check the format:
uv run .claude/skills/testcase-generator/scripts/validate.py \
--single "test-case/{模块}/{测试点}.md"
The script outputs logs indicating format issues (such as incorrect priority, missing fields, etc.). The AI analyzes the logs and decides whether modifications are needed.
Step 2: After all generation is complete
Call the validation script again for an overall check:
uv run .claude/skills/testcase-generator/scripts/validate.py "test-case/" --check-duplicates
The script checks for duplicate test cases, format consistency, etc. The script only provides logs and does not directly modify files. The AI analyzes the logs and decides whether adjustments are needed.
Step 3: Generate quality report
- Count test cases (by ITEM, by priority)
- Count equivalence class coverage
- Count boundary value coverage
- List duplicate test cases (if any)
9. Checklist
Pre-generation check
- Read
test-case/plan.md - Read
clarified-requirements/index.md - Read
CLAUDE.mdbusiness context - Understand the hierarchical relationship between test items (ITEM) and test points (POINT)
Check when generating each POINT
- A test case file has been generated for each POINT
- The number of test cases is reasonable (based on scenario complexity)
- All test cases have a priority (P1-P5)
- All test cases have a test type (one of 12)
- Test data is specific (no placeholders)
- Expected results are verifiable (no vague descriptions)
- The number of test steps matches the number of expected results
- Test case titles start with "Verify"
Governance phase check
- The global validation script was executed
- Duplicate test cases were checked
- The format complies with the specification (already checked by validate.py)
- all_cases.md has been generated
- No duplicate test cases (already checked by validate.py --check-duplicates)
- Quality report generated
10. Script Interface
validate.py
# 单文件校验
uv run .claude/skills/testcase-generator/scripts/validate.py \
--single "test-case/{模块}/{测试点}.md"
# 全局校验
uv run .claude/skills/testcase-generator/scripts/validate.py "test-case/"
# 全局校验 + 重复检测
uv run .claude/skills/testcase-generator/scripts/validate.py "test-case/" --check-duplicates
# 仅重复检测
uv run .claude/skills/testcase-generator/scripts/validate.py "test-case/" --duplicates-only
Validation Item:
- Schema format
- Required fields (priority, test type, test steps, expected results)
- Test type enumeration (12 types)
- Step number continuity
- Consistency between number of steps and expected results
- Equivalence class coverage check (
--check-equivalence) - Boundary value coverage check (
--check-boundary) - Duplicate detection (
--check-duplicates)
to_excel.py
# 从目录导出
uv run .claude/skills/testcase-generator/scripts/to_excel.py "test-case/" -o "test-case/export.xlsx"
# 从单个文件导出
uv run .claude/skills/testcase-generator/scripts/to_excel.py "test-case/{模块}/{测试点}.md" -o "output.xlsx"
11. Exception Handling
| Error | Handling Method |
|---|---|
| Single file validation failed | Retry 3 times; if still failed, skip and log |
| Too many test cases (>15) | Prompt to check for redundant equivalence classes |
| Missing boundary test cases | Warn and recommend adding |
| Missing invalid equivalence classes | Warn and recommend adding exception scenarios |
| Step numbers not continuous | Report error and require correction |
| Test type not in enumeration | Report error and require correction |
| Inconsistent number of steps and expected results | Report error and require correction |
| Export failed | Check openpyxl dependency |
12. Stopping Point
✅ Test case generation completed
Artifacts:
test-case/{ITEM}/{POINT}.md- Test case files for each test pointtest-case/all_cases.md- Summary of all test cases
Quality Assurance:
- Generated based on equivalence class theory
- Full boundary value coverage
- Reasonable number of test cases (based on scenario complexity)
Statistics Example:
📊 生成统计:
- 测试项: 8个
- 测试点: 20个
- 测试用例: 75个
覆盖率:
- 有效等价类: 100% (每POINT至少1个)
- 无效等价类: 80% (主要异常全覆盖)
- 边界值: 90% (所有范围型输入)
用例分布:
- P1(核心正向): 20个(27%)
- P2(基本正向): 15个(20%)
- P3(核心异常): 25个(33%)
- P4(边界条件): 12个(16%)
- P5(低频场景): 3个(4%)
Next Steps:
- Manually review test cases
- Export to Excel format (optional)
- Adjust test cases based on business understanding