generate-test-cases
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenerate Test Cases Skill
Generate Test Cases 技能
You will analyze code and generate a list of test cases that should be written for a given method/class. This skill outputs test case descriptions only — it does NOT generate actual test code.
Target to analyze: $ARGUMENTS
你将分析代码并生成针对给定方法/类应编写的测试用例列表。本技能仅输出测试用例描述——不生成实际测试代码。
分析目标: $ARGUMENTS
Quality Standards
质量标准
- Take your time to analyze the code thoroughly before listing test cases.
- Quality is more important than speed — read all relevant source files and rules carefully.
- Do not skip reading the dependency classes. Understanding the full context produces better test cases.
- 列出测试用例前,请花时间彻底分析代码。
- 质量比速度更重要——请仔细阅读所有相关源文件和规则。
- 不要跳过依赖类的阅读。了解完整上下文才能生成更优质的测试用例。
Instructions
操作步骤
Step 1: Read Rules and Analyze Context
步骤1:阅读规则并分析上下文
- Read the rules from directory (see Rules Reference below)
./rules/general/ - Read the target source file/class/method specified above
- Read dependencies: Follow imports to read DTOs, entities, enums, and other types referenced by the target (as specified in rule)
code-context-analysis - Check for existing tests: Search for existing test classes covering this target (as specified in rule) — if found, read it fully and focus only on behaviors not yet covered
existing-test-awareness
- 阅读规则:从目录读取规则(见下方规则参考)
./rules/general/ - 阅读目标对象:读取上方指定的源文件/类/方法
- 阅读依赖项:根据导入关系读取目标对象引用的DTO、实体、枚举及其他类型(遵循规则)
code-context-analysis - 检查现有测试:搜索覆盖该目标对象的现有测试类(遵循规则)——如果找到,请完整阅读并仅关注未覆盖的行为
existing-test-awareness
Step 2: Generate Test Cases
步骤2:生成测试用例
- Analyze ALL code branches, including:
- Success paths
- Error/exception paths
- Validation logic
- Private/protected methods called by the target
- Security annotations (if present)
- Apply the INCLUDE/EXCLUDE rules strictly
- Output the list of test cases in the specified format
- Do NOT generate actual test code — only the test case descriptions
- 分析所有代码分支,包括:
- 成功路径
- 错误/异常路径
- 验证逻辑
- 目标对象调用的私有/受保护方法
- 安全注解(若存在)
- 严格遵循INCLUDE/EXCLUDE规则
- 按指定格式输出测试用例列表
- 不生成实际测试代码——仅输出测试用例描述
Output Format
输出格式
For each test case, provide:
undefined每个测试用例需包含:
undefinedTest Cases for {ClassName}.{methodName}
Test Cases for {ClassName}.{methodName}
1. {testMethodName}
1. {testMethodName}
- Given: {preconditions/input state}
- When: {action being tested}
- Then: {expected outcome}
- Code branch: {which code path this covers}
- Given: {preconditions/input state}
- When: {action being tested}
- Then: {expected outcome}
- Code branch: {which code path this covers}
2. {testMethodName}
2. {testMethodName}
...
undefined...
undefinedNaming Convention
命名规范
Test method name format:
{testedMethod}_{givenState}_{expectedOutcome}Examples:
calculateTotal_validProducts_returnsSumcalculateTotal_emptyList_throwsIllegalArgumentExceptiongetUser_unauthorized_returns401getUser_forbidden_returns403
测试方法命名格式:
{testedMethod}_{givenState}_{expectedOutcome}示例:
calculateTotal_validProducts_returnsSumcalculateTotal_emptyList_throwsIllegalArgumentExceptiongetUser_unauthorized_returns401getUser_forbidden_returns403
Troubleshooting
问题排查
Target file not found
目标文件未找到
If the specified target does not exist, inform the user with the exact path you searched and ask for clarification.
如果指定的目标对象不存在,请告知用户你搜索的准确路径并请求澄清。
Unsupported language
不支持的语言
If the target code is in a language without specific rules, apply only the general rules and inform the user.
如果目标代码使用的语言没有特定规则,仅应用通用规则并告知用户。
All behaviors already covered
所有行为已被覆盖
If the existing test class already covers all identified behaviors, output a summary stating that coverage is complete. List what is already tested. Do not invent additional test cases to justify the analysis.
如果现有测试类已覆盖所有识别到的行为,输出总结说明覆盖率已完成,并列出已测试的内容。请勿为了完成分析而编造额外测试用例。
Example
示例
User says: "/generate-test-cases src/main/java/com/example/service/OrderService.java"
Step 1: Agent reads rules, reads OrderService.java, reads OrderRequest.java,
Order.java (dependencies), checks for existing OrderServiceTest.java.
Step 2: Agent outputs:User says: "/generate-test-cases src/main/java/com/example/service/OrderService.java"
Step 1: Agent reads rules, reads OrderService.java, reads OrderRequest.java,
Order.java (dependencies), checks for existing OrderServiceTest.java.
Step 2: Agent outputs:Test Cases for OrderService.createOrder
Test Cases for OrderService.createOrder
1. createOrder_validRequest_savesAndReturnsOrder
1. createOrder_validRequest_savesAndReturnsOrder
- Given: Valid OrderRequest with productId "product-1" and quantity 5
- When: createOrder is called
- Then: Order is saved to repository and returned with generated ID
- Code branch: Success path
- Given: Valid OrderRequest with productId "product-1" and quantity 5
- When: createOrder is called
- Then: Order is saved to repository and returned with generated ID
- Code branch: Success path
2. createOrder_nullProductId_throwsIllegalArgumentException
2. createOrder_nullProductId_throwsIllegalArgumentException
- Given: OrderRequest with null productId
- When: createOrder is called
- Then: IllegalArgumentException is thrown
- Code branch: Validation — productId null check ...
---- Given: OrderRequest with null productId
- When: createOrder is called
- Then: IllegalArgumentException is thrown
- Code branch: Validation — productId null check ...
---Rules Reference
规则参考
CRITICAL: You MUST read and apply all rules from the following files before generating test cases:
Maintenance note: General rules inare shared with the./rules/general/skill (which has copies ingenerate-tests). When updating rules, keep both locations in sync.rules/tests/general/
重要提示:生成测试用例前,你必须阅读并应用以下文件中的所有规则:
维护说明:中的通用规则与./rules/general/技能共享(该技能的规则副本位于generate-tests)。更新规则时,请保持两个位置的内容同步。rules/tests/general/
General Rules (Always Apply)
通用规则(始终适用)
- - INCLUDE/EXCLUDE criteria for test cases
./rules/general/test-case-generation-strategy.md - - Test naming format
./rules/general/naming-conventions.md - - Core testing principles
./rules/general/general-principles.md - - Clarity, Completeness, Conciseness, Resilience
./rules/general/what-makes-good-test.md - - One scenario per test
./rules/general/keep-tests-focused.md - - Separate tests for behaviors
./rules/general/test-behaviors-not-methods.md - - Test public APIs over private methods
./rules/general/prefer-public-apis.md - - Use helpers and builders for test data
./rules/general/cleanly-create-test-data.md - - Effects follow causes immediately
./rules/general/keep-cause-effect-clear.md - - KISS > DRY, avoid logic in assertions
./rules/general/no-logic-in-tests.md - - Detect language and framework
./rules/general/technology-stack-detection.md - - Only verify relevant mock arguments
./rules/general/verify-relevant-arguments-only.md - - Check for existing tests, avoid duplicates
./rules/general/existing-test-awareness.md - - Read dependencies before analyzing
./rules/general/code-context-analysis.md
- - 测试用例的INCLUDE/EXCLUDE标准
./rules/general/test-case-generation-strategy.md - - 测试命名格式
./rules/general/naming-conventions.md - - 核心测试原则
./rules/general/general-principles.md - - 清晰性、完整性、简洁性、韧性
./rules/general/what-makes-good-test.md - - 每个测试对应一个场景
./rules/general/keep-tests-focused.md - - 为不同行为分别编写测试
./rules/general/test-behaviors-not-methods.md - - 优先测试公开API而非私有方法
./rules/general/prefer-public-apis.md - - 使用辅助工具和构建器创建测试数据
./rules/general/cleanly-create-test-data.md - - 确保因果关系直接明确
./rules/general/keep-cause-effect-clear.md - - 遵循KISS原则而非DRY原则,避免在断言中加入逻辑
./rules/general/no-logic-in-tests.md - - 检测语言与框架
./rules/general/technology-stack-detection.md - - 仅验证相关的Mock参数
./rules/general/verify-relevant-arguments-only.md - - 检查现有测试,避免重复
./rules/general/existing-test-awareness.md - - 分析前先阅读依赖项
./rules/general/code-context-analysis.md