case-generator
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "case-generator" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-3527ff953b3e093c29c99bd8fb565c8cf0d78992e85cc0eef57cf9f3a5d991ef. Verify the upstream source and version against https://skillhub.cn/skills/user_3ddd765c/case-generator before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Generate framework-compliant Python automation test code based on scenarios and data assets in the test_plan, following the default_Case code style, for invocation by the qa-integration-pipeline Phase 4.
Introduction source: third_party · user_3ddd765c · 1.0.5 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Inputs and outputs
- Translation pending; see source documentation.
- Software, accounts and paid services
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: case-generator
description: 基于 test_plan 中的场景设计和数据资产,参考 default_Case 代码风格,生成符合框架规范的 Python 自动化测试代码。供 qa-integration-pipeline Phase 4 调用。
slug: case-generator
version: 1.0.5
displayName: Case Generator
changelog:
- '1.0.5: 增加 Step 0 知识库查询功能'
- '1.0.4: Step 6 push分支从可选改为必须,Jenkins回归Job依赖远程分支拉取case'
- '1.0.2: 泛化data_assets参数说明支持md/json'
- '1.0.0: 初始版本,整合场景解析 + 代码生成'功能 Case 生成器
角色定位
本 Skill 是 Phase 4 子 Skill,职责:
- 读取
test_plan.md中的测试场景设计(场景列表、预期行为、验证方式) - 读取
data_assets文件中的可用数据资产(坐标、响应样本) - 参考
default_Case/下的现有代码风格和框架规范 - 生成符合
navi_guide_tools框架的 Python 自动化测试代码 - 输出可直接运行的
test_<feature>.py和配套文件
本 Skill 自动执行,不中断询问用户。所有交互交由上游
qa-integration-pipeline处理。执行方式:代码生成由 AI 侧完成,无需外部工具调用。生成后如需运行测试,通过 Jenkins MCP 触发。
输入参数
| 参数 | 必填 | 说明 |
|---|---|---|
feature |
✅ | 功能名,用于类名、文件名和分支名 |
test_plan |
✅ | test_plan.md 路径 |
data_assets |
❌ | 数据资产文件路径(Phase 3 产物,如 data/filter_analysis.md 索引文件或 .json 数据文件) |
design_doc |
❌ | design.md 路径(辅助理解实现细节) |
default_case_dir |
❌ | default_Case 模板目录,默认 /home/xiaoju/map-spec/navi_guide_tools/case/default_Case/ |
regression_project_dir |
❌ | 回归工程根目录,默认 /home/xiaoju/map-spec/navi_guide_tools/。对应仓库 git@git.xiaojukeji.com:map-qa/navi_guide_tools.git。新生成的 case 将放置到该目录并创建 feature 分支 |
执行步骤
Step 0: 知识库查询(可选)
在执行代码生成前,可查询 LLM-Wiki 知识库获取历史用例代码风格和框架使用经验:
POST http://10.190.56.84:8080/search
Content-Type: application/json
{
"collection": "navi-guide-qa-knowledge",
"query": "<feature> 历史用例代码风格 TestBase build_request",
"limit": 5
}
查询时机:
- Step 4 参考 default_Case 前:查询同类功能的历史 case,了解代码风格和断言模式
- 遇到框架使用疑问时:查询
TestBase、build_request、call_target的使用规范
检索结果应用:
- 将检索到的历史 case 风格作为生成代码的参考
- 若检索结果与
default_case_dir模板冲突,以default_case_dir为准
Step 1: 前置校验
- 校验参数完整性:
feature、test_plan - 校验
test_plan.md存在且可读 - 校验
default_case_dir存在,关键模板文件完整 - 如提供
data_assets,校验文件存在 - 检查/初始化回归工程:
- 检查
/home/xiaoju/map-spec/navi_guide_tools/目录是否存在且为 git 仓库(.git存在) - 若不存在 → clone 回归工程到固定目录:
git clone git@git.xiaojukeji.com:map-qa/navi_guide_tools.git /home/xiaoju/map-spec/navi_guide_tools/ - 若已存在 → 切到 master 分支并拉取最新:
cd /home/xiaoju/map-spec/navi_guide_tools/ git checkout master git pull origin master - 若已存在但不是 git 仓库 → 报错,要求清理后重新 clone
- 检查
- 确认输出目录:
/home/xiaoju/map-spec/navi_guide_tools/case/AI_Case/<feature>/
Step 2: 读取并解析测试场景
从 test_plan.md 提取:
| 提取项 | 来源章节 | 用途 |
|---|---|---|
| 场景列表 | 二、测试场景设计 → 2.1 场景列表 | 每个场景生成一个 test 方法 |
| 数据筛选条件 | 二、测试场景设计 → 2.2 数据筛选条件 | 构造请求参数 |
| 预期行为 | 2.1 场景列表中的 expected_behavior |
生成断言 |
| 验证方式 | 2.1 场景列表中的 验证方式 |
决定断言类型(协议字段 / 日志 / 协议+日志) |
| Apollo 开关 | 三、执行策略 → 3.1 功能开关控制 | 注入开关配置 |
| AB 实验配置 | 三、执行策略 → 3.1 功能开关控制 | 注入实验参数 |
场景解析示例:
| 场景ID | 场景描述 | trigger_condition | expected_behavior | 验证方式 |
|--------|---------|-------------------|-------------------|---------|
| S001 | 连续路口合并播报 | distance < 200m, 两个连续路口 | ttsContent 合并为一条播报, voiceType = MERGE_VOICE | 协议字段 |
解析为:
- 方法名:
test_continuous_merge_voice - 请求构造:
distance=150,scene_type=CONTINUOUS_INTERSECTION - 断言:
assert resp.voice.ttsContent == "...",assert resp.voice.voiceType == "MERGE_VOICE"
Step 3: 读取数据资产
从 data_assets 文件提取(如提供):
- 可用坐标列表 → 硬编码到测试代码中或参数化
- 响应样本 → 作为预期值参考
- 场景覆盖映射 → 确保每个场景有对应数据
数据引用方式:
- 有具体坐标数据 → 直接写入代码或读取 JSON
- 无具体坐标 → 使用
build_request()构造通用请求
Step 4: 参考 default_Case 代码风格
读取模板代码,提取框架规范:
# 典型结构示例(来自 default_Case)
import unittest
from navi_guide_tools.case.lib import TestBase
class TestDefaultCase(TestBase):
def build_request(self, **kwargs):
# 构造请求的统一入口
...
def call_target(self, req):
# 调用目标服务的统一入口
...
需遵循的规范:
- 继承
TestBase - 使用
build_request()构造请求 - 使用
call_target()调用服务 - 断言使用
self.assertEqual、self.assertIn等标准方法 - 如有 Apollo 开关,通过
self.set_apollo_config()注入 - 如有 AB 实验,通过
self.set_abtest_params()注入
Step 5: 生成测试代码
输出文件:
| 文件 | 路径 | 说明 |
|---|---|---|
| 主测试文件 | /home/xiaoju/map-spec/navi_guide_tools/case/AI_Case/<feature>/test_<feature>.py |
核心测试代码(直接输出到回归工程目录) |
| 初始化文件 | /home/xiaoju/map-spec/navi_guide_tools/case/AI_Case/<feature>/__init__.py |
包初始化 |
| 数据文件(可选) | /home/xiaoju/map-spec/navi_guide_tools/case/AI_Case/<feature>/test_data.json |
坐标/响应样本数据 |
代码生成规则:
- 类名:
class case(unittest.TestCase)(参考历史 case 格式,统一类名) - 方法名:
test_<scene_description_snake_case> - Docstring:场景描述(来自 test_plan)
- 请求构造:
- 从 trigger_condition 提取参数
- 调用
self.build_request(...) - 如需 Apollo 开关,前置调用
self.set_apollo_config(key, value)
- 断言生成:
验证方式 = 协议字段→ 对响应字段做assertEqual/assertIn验证方式 = 日志→ 标记为日志验证(生成注释说明)验证方式 = 协议+日志→ 协议断言 + 日志验证注释
- 数据引用:
- 有坐标数据 → 参数化或硬编码
- 无坐标数据 → 使用通用构造器
- 灰度开关控制(参考历史 case 格式):
- 每个 test 方法必须添加
@unittest.skipUnless(globalSwitch.ai_case_<feature>, "<功能描述>")装饰器 - 在文件头部
import globalSwitch
- 每个 test 方法必须添加
- 代码风格参考:读取
default_Case/下 2-3 个历史 case 文件,提取 Header、Imports、Class Structure、Request Construction、Response Parsing 等关键模式
生成示例:
import unittest
from navi_guide_tools.case.lib import TestBase
class TestContinuousActionMerge(TestBase):
"""连续动作合并播报功能测试"""
def test_s001_continuous_merge_voice(self):
"""S001: 连续路口合并播报"""
# 注入 Apollo 开关
self.set_apollo_config("p_docker_dev_sl_continuous_action_merge", True)
# 构造请求:连续路口场景
req = self.build_request(
scene_type="CONTINUOUS_INTERSECTION",
distance=150,
version=490
)
# 调用目标服务
resp = self.call_target(req)
# 验证协议字段
self.assertIn("前方连续路口", resp.voice.ttsContent)
self.assertEqual(resp.voice.voiceType, "MERGE_VOICE")
self.assertTrue(resp.voice.mergeFlag)
def test_s002_no_merge_normal_voice(self):
"""S002: 非连续路口正常播报"""
self.set_apollo_config("p_docker_dev_sl_continuous_action_merge", True)
req = self.build_request(
scene_type="SINGLE_INTERSECTION",
distance=150,
version=490
)
resp = self.call_target(req)
# 不应触发合并
self.assertNotIn("连续", resp.voice.ttsContent)
self.assertEqual(resp.voice.voiceType, "NORMAL")
Step 6: 放置代码到回归工程并创建分支
目的:将生成的 case 放入回归工程固定目录,并创建 feature 分支,供后续回归 Job 执行。
操作步骤:
-
进入回归工程目录:
cd <regression_project_dir> -
确保 master 最新,再创建/切换 feature 分支(分支名:
<feature>):git checkout master git pull origin master git checkout <feature> 2>/dev/null || git checkout -b <feature>先切回 master 拉取最新,确保新分支基于最新 master 创建;若本地分支已存在则直接切换。
-
创建 case 目录(如不存在):
mkdir -p case/AI_Case/<feature>/ -
写入生成的代码文件:
case/AI_Case/<feature>/test_<feature>.pycase/AI_Case/<feature>/__init__.pycase/AI_Case/<feature>/test_data.json(如有)
-
注册 feature 开关到
globalSwitch.py:- 读取
case/globalSwitch.py - 在文件末尾追加新的 feature 开关变量:
ai_case_<feature> = True # AI generated test cases for <feature> - 变量命名规则:
ai_case_<feature_snake_case>,与 test_plan 中的功能名保持一致 - 生成的 test 方法需使用
@unittest.skipUnless(globalSwitch.ai_case_<feature>, "...")装饰器(参考历史 case 格式)
- 读取
-
提交代码:
git add case/AI_Case/<feature>/ case/globalSwitch.py git commit -m "[AI] Add test cases and globalSwitch for <feature>" -
推送分支到远程仓库(必须,供 Jenkins 回归 Job 拉取):
git push -u origin <feature>若推送失败(网络/权限问题),记录错误并返回
{"status": "failed", "reason": "分支推送失败", "detail": "..."},阻断后续 Phase。若远程已存在同名分支,使用
git push -f origin <feature>强制更新(覆盖旧 case)。
注意:若分支已存在(断点续跑场景),直接
git checkout <feature>并覆盖更新后重新提交。
Step 7: 代码自检
生成完成后执行以下检查:
- [ ] 类名规范:统一为
class case(unittest.TestCase)(参考历史 case 格式) - [ ] 方法名规范:以
test_开头,snake_case - [ ] 字段存在性:所有断言中的字段必须是协议中存在的字段(黑盒约束)
- [ ] 场景覆盖:test_plan 中每个场景都有对应的 test 方法
- [ ] 数据引用:如引用了 data_assets 中的坐标,确保路径正确
- [ ] Apollo 开关:如 test_plan 中有开关配置,代码中已注入
- [ ] AB 实验:如 test_plan 中有 AB 实验,代码中已配置实验参数
- [ ] 语法正确:生成的代码可通过 Python 语法检查
- [ ] 回归工程分支已创建:
<feature>分支存在且代码已提交
Step 8: 返回结果
向 qa-integration-pipeline 返回执行摘要:
{
"status": "success",
"test_file": "/home/xiaoju/map-spec/navi_guide_tools/case/AI_Case/<feature>/test_<feature>.py",
"scene_count": 5,
"method_count": 8,
"coverage": {
"protocol_assertion": 6,
"log_assertion": 2,
"protocol_log_assertion": 1
},
"data_referenced": true,
"self_check_passed": true,
"regression_project_dir": "<regression_project_dir>",
"case_branch": "<feature>"
}
case_branch为回归工程 feature 分支名,qa-integration-pipeline Phase 5 调用 regression-executor-and-analyzer 时需使用此分支名作为case_branch参数。
产物清单
| 产物 | 路径 |
|---|---|
| 主测试文件 | /home/xiaoju/map-spec/navi_guide_tools/case/AI_Case/<feature>/test_<feature>.py |
| 包初始化文件 | /home/xiaoju/map-spec/navi_guide_tools/case/AI_Case/<feature>/__init__.py |
| 测试数据文件(可选) | /home/xiaoju/map-spec/navi_guide_tools/case/AI_Case/<feature>/test_data.json |
失败处理
| 失败场景 | 处理 |
|---|---|
| test_plan.md 中无场景列表 | 返回 {"status": "failed", "reason": "test_plan.md 中未定义测试场景"} |
| default_Case 模板不存在 | 返回 {"status": "failed", "reason": "default_Case 模板目录不存在"} |
| 场景解析失败(字段不明确) | 返回 {"status": "failed", "reason": "场景解析失败", "detail": "..."} |
| 代码生成后语法错误 | 自动修复(最多 3 轮)→ 仍失败则返回错误 |
| 场景覆盖不完整 | 返回 {"status": "warning", "reason": "部分场景未生成对应 test 方法", "missing_scenes": [...]} |
与 qa-integration-pipeline 的协作
qa-integration-pipeline (Phase 4)
└── 调用 case-generator
├── 读取 test_plan 场景设计
├── 读取 data_assets 数据资产(可选)
├── 参考 default_Case 代码风格
├── 生成 test_<feature>.py
├── 代码自检
└── 返回生成摘要
└── qa-integration-pipeline 决策:
- self_check_passed == true → 继续 Phase 5(regression)
- 有 warning → 标记继续,但记录风险
- failed → 询问用户或重试
与下游模块的协作
与 regression-runner(Phase 5)
- 生成的
test_<feature>.py可被回归套件收录 - 新增 case 自动加入回归用例集
与 test-executor(运行时)
- 生成的代码兼容
TestBase框架 - 支持响应注入和结果收集
与 ng-case-reporter(上报)
- 生成的 test 方法可被扫描并上报到
qa_ai_testcase_detail
Current listing version
1.0.5
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 作为 QA 集成流水线 Phase 4 的核心子 Skill,直接解决自动化测试用例生成的刚需痛点
- 功能闭环完整,从场景解析到代码生成再到回归工程集成,显著提升测试效率
Highlights
- description 清晰明确,精准描述基于 test_plan 和 data_assets 生成 Python 自动化测试代码的核心功能
- 明确指明供 qa-integration-pipeline Phase 4 调用,触发边界清晰
Areas to improve
-
description写错位置 Reported severity: Minor
顶层 frontmatter 与 skill_body 内部均包含 description,存在重复
Recommendation: 建议仅保留顶层 frontmatter 中的 description,移除 skill_body 内部的重复描述
Highlights
- 文档结构清晰完整,包含角色定位、输入参数、8 个详细执行步骤、产物清单、失败处理及协作说明
- 步骤划分明确,有端到端代码生成示例,frontmatter 完整
Highlights
- 工具来源明确(git clone、HTTP 请求),参数校验完整
- 覆盖主要异常场景(文件不存在、git 仓库异常、推送失败等),代码生成后含自检机制
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- 10.190.56.84
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Translation pending; see source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.