决定测试MCP
Claude驱动的测试工作流程 根据决策生成测试用例 表,为测试计划提供智能指导,并生成 可执行测试代码。
特性
- 🤖 克劳德驱动测试计划:通过MCP与Claude合作进行智能测试指导
- 📊 决策表解析:支持CSV、JSON和Markdown格式
- 🎭 剧作家整合:生成可执行的Playwright测试
- 🔌 API测试:创建具有正确身份验证的API测试套件
- 🔧 MCP服务器:与Claude Code无缝集成
- 📝 TypeScript支持:生成类型安全测试代码
- 💰 零成本:不需要外部API密钥
安装
作为MCP服务器(用于克劳德代码)
- 构建包:
pnpm install
pnpm build- 添加到克劳德代码MCP配置 (
~/.claude-code/mcp.json):
{
"mcpServers": {
"decide-test": {
"command": "node",
"args": ["/absolute/path/to/dist/index.js"]
}
}
}- 重新启动Claude代码
作为独立包装
pnpm install
pnpm build用法
通过克劳德代码
安装MCP服务器后,您可以在Claude Code中使用它:
Generate test cases from the decision table at docs/examples/decision-tables/login-decision-table.csv克劳德代码将:
- 解析决策表
- 使用AI代理探索每个测试用例
- 生成Playwright测试代码
- 保存到
tests/e2e/generated/
程序化使用
import {
decisionTableParser,
WebAgent,
testCodeGenerator
} from 'decide-test-mcp';
// 1. Parse decision table
const table = await decisionTableParser.parse(
'docs/examples/decision-tables/login-decision-table.csv'
);
// 2. Get guidance for test planning (you provide the steps)
const webAgent = new WebAgent();
const testSteps = [];
for (const testCase of table.test_cases) {
// Get guidance (example steps and recommendations)
const guidance = webAgent.getExplorationGuidance({
url: 'http://localhost:3000',
test_case: testCase,
objective: testCase.name,
});
console.log(guidance.suggested_approach);
console.log('Example steps:', guidance.example_steps);
// You define the actual test steps based on guidance
const steps = [
{ action: 'navigate', target: 'http://localhost:3000/login', description: 'Go to login' },
{ action: 'fill', selector: 'input[name="email"]', value: 'test@example.com', description: 'Enter email' },
{ action: 'click', selector: 'button[type="submit"]', description: 'Click login' },
];
testSteps.push({
test_case_id: testCase.id,
type: 'web',
steps,
});
}
// 3. Generate test code
const generated = await testCodeGenerator.generate({
test_cases: table.test_cases,
steps: testSteps,
framework: 'playwright',
output_path: 'tests/e2e/generated/',
language: 'typescript',
});
console.log(`Generated ${generated.files_generated.length} test files`);MCP工具
1.解析决策表
解析决策表并生成测试用例规范。
示例:
{
"table_path": "docs/examples/decision-tables/login-decision-table.csv",
"format": "csv"
}2.网站测试指南
获取规划web测试的指导和示例步骤。Claude使用它来了解要创建哪些测试步骤。
示例:
{
"url": "http://localhost:3000",
"test_case": {...},
"objective": "Login with valid credentials"
}退货:建议的方法、示例步骤和克劳德计划实际测试步骤的指导。
3.执行web测试
使用Playwright执行预定义的web测试步骤。
示例:
{
"url": "http://localhost:3000",
"test_case": {...},
"objective": "Login with valid credentials",
"steps": [
{ "action": "navigate", "target": "http://localhost:3000/login", "description": "Go to login" },
{ "action": "fill", "selector": "input[name='email']", "value": "test@example.com", "description": "Enter email" },
{ "action": "click", "selector": "button[type='submit']", "description": "Click login" }
],
"headless": true,
"screenshot_dir": "./screenshots"
}4.获取pi_test_guidance
获取规划API测试的指导和示例步骤。
示例:
{
"base_url": "http://localhost:3000/api",
"test_case": {...},
"objective": "Create trip via API",
"auth": {
"type": "bearer",
"credentials": {"token": "..."}
}
}退货:建议的方法,例如API步骤,以及Claude计划实际API测试步骤的指导。
5.执行api测试
执行预定义的API测试步骤。
示例:
{
"base_url": "http://localhost:3000/api",
"test_case": {...},
"objective": "Create trip via API",
"steps": [
{ "method": "POST", "endpoint": "/auth/login", "body": {...}, "expected_status": 200 },
{ "method": "POST", "endpoint": "/trips", "body": {...}, "expected_status": 201 }
],
"auth": {
"type": "bearer"
}
}6.生成测试代码
从测试用例和步骤生成可执行的测试代码。
示例:
{
"test_cases": [...],
"steps": [...],
"framework": "playwright",
"output_path": "tests/e2e/generated/",
"language": "typescript"
}7.run_generated测试
执行生成的测试并返回结果。
示例:
{
"test_path": "tests/e2e/generated/login.spec.ts",
"framework": "playwright",
"reporter": "list"
}决策表格式
CSV格式
Email,Password,Action,Expected Result,Priority
valid@example.com,ValidPass123,Click Login,Login successful,high
invalid@example.com,ValidPass123,Click Login,Show error message,mediumJSON格式
{
"feature": "User Login",
"rules": [
{
"id": "TC001",
"conditions": {
"email": "valid",
"password": "valid"
},
"actions": ["click_login"],
"expected": ["redirect_to_dashboard"]
}
]
}Markdown格式
# User Login
| Email | Password | Action | Expected Result |
|-------|----------|--------|----------------|
| valid | valid | Click Login | Login successful |
| invalid | valid | Click Login | Show error |示例
看 docs/examples/decision-tables/ 完整示例:
login-decision-table.csv-用户身份验证测试trip-creation-decision-table.json-创建具有等级限制的行程collaboration-decision-table.md-协作和权限
发展
# Install dependencies
pnpm install
# Build
pnpm build
# Run in development mode
pnpm dev
# Run tests
pnpm test建筑
┌─────────────────────────────────────┐
│ MCP Server │
│ (Model Context Protocol) │
└─────────────────────────────────────┘
│
┌─────────┼─────────┐
│ │ │
▼ ▼ ▼
┌────────┐ ┌──────┐ ┌──────────┐
│ Parser │ │Agents│ │Generator │
└────────┘ └──────┘ └──────────┘故障排除
Claude代码中未出现MCP服务器
- 检查MCP配置路径是否正确
- 验证Node.js是否可访问
- 检查服务器日志:
~/.claude-code/logs/mcp-ai-testing.log - 重新启动Claude代码
测试执行失败
- 检查应用程序是否在指定的URL上运行
- 审查测试步骤的正确性
- 试试看
headless: false查看浏览器的运行情况 - 检查选择器的特异性
测试生成问题
- 确保测试用例和步骤完整
- 检查输出目录权限
- 检查生成的代码是否存在语法错误
许可证
麻省理工学院
支持
对于问题和疑问:
- 文档:
docs/AI_TESTING_WORKFLOW.md
