Manus에서 모든 스킬 실행
원클릭으로
원클릭으로
원클릭으로 Manus에서 모든 스킬 실행
시작하기test-generation
스타0
포크0
업데이트2025년 12월 27일 12:56
使用 Minion 框架生成智能测试用例
설치
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SKILL.md
readonly메뉴
使用 Minion 框架生成智能测试用例
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
ECharts图表配置技能,包括柱状图、折线图、组合图等可视化组件
车险经营数据导入技能,支持CSV/JSON解析、验证、优先级管理
KPI指标计算技能,包括目标拆解、达成率、增长率、时间进度等核心业务计算
使用 Minion 框架进行智能业务分析
使用 Minion 框架进行智能代码审查
使用 Minion 框架进行智能数据验证
| name | test-generation |
| description | 使用 Minion 框架生成智能测试用例 |
| license | MIT |
| version | 1.0.0 |
| category | minion-integration |
此技能提供基于 Minion 的测试用例生成能力,特别关注业务逻辑测试、边界条件测试、文档驱动测试。与项目 Vitest 框架集成,自动生成高质量测试。
选择目标(代码或文档)
↓
Claude Code 调用此 Skill
↓
提取测试场景
↓
调用 Minion 生成测试
↓
返回测试代码
↓
集成到测试套件
// 1. 选择目标函数
const targetFunction = 'calculateAchievementRate';
// 2. 读取函数和文档
import { readFunctionCode } from '@/lib/code-utils';
import { extractBusinessDoc } from '@/lib/doc-utils';
const functionCode = await readFunctionCode(targetFunction);
const businessDoc = await extractBusinessDoc(functionCode);
// 3. 调用 Minion 生成测试
import { callMinionAPI } from '@/lib/minion-client';
const tests = await callMinionAPI({
endpoint: '/api/generate-tests',
method: 'POST',
body: {
target: {
type: 'function',
name: targetFunction,
code: functionCode,
documentation: businessDoc
},
framework: 'vitest',
options: {
includeBoundaryTests: true,
includeNullTests: true,
coverage: 'high'
}
}
});
// 4. 写入测试文件
await writeTestFile(targetFunction, tests.content);
// 5. 运行测试
import { exec } from 'child_process';
await exec('pnpm test ' + tests.testFile);
项目使用 Vitest:
// vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
globals: true,
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html']
}
}
});
// 使用 @doc 标签定位业务文档
const docPath = extractDocTag(functionCode);
const docContent = await readDocFile(docPath);
// 提取测试场景
const scenarios = await callMinionAPI({
endpoint: '/api/extract-scenarios',
method: 'POST',
body: {
documentation: docContent
}
});
// 生成测试代码
const tests = await callMinionAPI({
endpoint: '/api/generate-tests',
method: 'POST',
body: {
scenarios: scenarios.scenarios,
targetFunction: functionCode,
framework: 'vitest'
}
});
Minion 生成的测试示例:
import { describe, it, expect } from 'vitest';
import { calculateAchievementRate } from '@/domain/achievement';
describe('calculateAchievementRate', () => {
it('should calculate achievement rate correctly', () => {
const result = calculateAchievementRate(8500, 10000);
expect(result).toBe(0.85);
});
it('should return null when target is 0', () => {
const result = calculateAchievementRate(8500, 0);
expect(result).toBeNull();
});
it('should return null when actual is null', () => {
const result = calculateAchievementRate(null, 10000);
expect(result).toBeNull();
});
it('should handle超额完成', () => {
const result = calculateAchievementRate(12000, 10000);
expect(result).toBe(1.2);
});
});
自动生成的边界测试:
describe('calculateAchievementRate - boundary conditions', () => {
it('should handle minimum non-zero value', () => {
const result = calculateAchievementRate(0.01, 10000);
expect(result).toBeCloseTo(0.000001);
});
it('should handle zero actual', () => {
const result = calculateAchievementRate(0, 10000);
expect(result).toBe(0);
});
it('should handle negative values', () => {
const result = calculateAchievementRate(-1000, 10000);
expect(result).toBeCloseTo(-0.1);
});
});
从文档提取的业务规则测试:
describe('calculateAchievementRate - business rules', () => {
it('should follow @doc specification', () => {
// 测试文档中定义的规则
const { actual, target } = getTestCaseFromDoc();
const expected = getExpectedFromDoc();
const result = calculateAchievementRate(actual, target);
expect(result).toBe(expected);
});
it('should comply with null-safety specification', () => {
// 文档要求:target 为 0 时返回 null
expect(calculateAchievementRate(100, 0)).toBeNull();
});
});
多个函数协作测试:
describe('Growth metrics calculation - integration', () => {
it('should calculate complete growth metrics', async () => {
const actuals = await loadActualsMonthly2026();
const targets = await loadTargetsAnnual2026();
const metrics = calculateGrowthMetrics(actuals, targets);
expect(metrics).toHaveProperty('growth_month_rate');
expect(metrics).toHaveProperty('inc_ytd');
expect(metrics.growth_month_rate).toBeGreaterThanOrEqual(0);
});
});
{
"target": {
"type": "function",
"name": "calculateAchievementRate",
"code": "export function calculateAchievementRate(actual: number, target: number): number | null {...}",
"documentation": "@doc docs/business/指标定义规范.md:120"
},
"framework": "vitest",
"options": {
"includeBoundaryTests": true,
"includeNullTests": true,
"coverage": "high"
}
}
{
"testFile": "src/domain/__tests__/calculateAchievementRate.test.ts",
"content": "import { describe, it, expect } from 'vitest';\n...",
"testCases": [
{
"name": "should calculate correctly",
"input": { "actual": 8500, "target": 10000 },
"expected": 0.85
},
{
"name": "should return null for zero target",
"input": { "actual": 8500, "target": 0 },
"expected": null
}
],
"coverageEstimate": "95%",
"recommendations": [
"Add tests for negative values",
"Consider adding performance tests for large datasets"
]
}
// ✅ 正确:清晰的测试组织
describe('FunctionName', () => {
describe('normal cases', () => {
it('should do X', () => {});
});
describe('boundary conditions', () => {
it('should handle Y', () => {});
});
describe('error cases', () => {
it('should throw Z', () => {});
});
});
// ❌ 错误:扁平结构
describe('FunctionName', () => {
it('test 1', () => {});
it('test 2', () => {});
// 15 个测试混在一起
});
// ✅ 正确:使用固定测试数据
const testCases = [
{ actual: 8500, target: 10000, expected: 0.85 },
{ actual: 0, target: 10000, expected: 0 }
];
// ❌ 错误:随机数据(不稳定)
const actual = Math.random() * 10000;
// 精确匹配
expect(result).toBe(0.85);
// 类型检查
expect(result).toBeNull();
expect(result).toBeNumber();
// 范围检查
expect(result).toBeGreaterThan(0);
expect(result).toBeLessThanOrEqual(1);
// 浮点数比较
expect(result).toBeCloseTo(0.85, 1);
| 层级 | 目标覆盖率 | 优先级 |
|---|---|---|
| Domain 层 | 100% | 最高 |
| Services 层 | 80%+ | 高 |
| Components 层 | 60%+ | 中 |
| Utils 层 | 90%+ | 高 |