npx skills add https://github.com/daffy0208/ai-dev-standards --skill 'Quality Assurance'质量保证是一个整合性技能,它结合了三个关键的质量维度:全面的测试策略、代码质量强制执行和阶段门验证。它确保您的代码在每个阶段都经过测试、可维护且已做好生产准备。
整合自:
在以下情况下使用质量保证:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
结构:
/\
/E2E\ 10% - 端到端测试 (关键用户流程)
/------\
/Integr-\ 20% - 集成测试 (组件、API、数据库)
/----------\
/ Unit \ 70% - 单元测试 (函数、类、逻辑)
/--------------\
原理:
覆盖率目标:
测试内容:
最佳实践:
示例:
// Good: Fast, isolated, clear
describe('calculateDiscount', () => {
it('applies 10% discount for orders over $100', () => {
const result = calculateDiscount(150)
expect(result).toBe(15)
})
it('returns 0 for orders under $100', () => {
const result = calculateDiscount(50)
expect(result).toBe(0)
})
it('throws error for negative amounts', () => {
expect(() => calculateDiscount(-10)).toThrow()
})
})
测试内容:
最佳实践:
示例:
// Good: Real database, tests integration
describe('POST /api/users', () => {
beforeEach(async () => {
await db.users.deleteMany({})
})
it('creates user and returns 201', async () => {
const response = await request(app)
.post('/api/users')
.send({ email: 'test@example.com', name: 'Test' })
expect(response.status).toBe(201)
expect(response.body.email).toBe('test@example.com')
const user = await db.users.findOne({ email: 'test@example.com' })
expect(user).toBeDefined()
})
it('returns 400 for duplicate email', async () => {
await db.users.create({ email: 'test@example.com' })
const response = await request(app)
.post('/api/users')
.send({ email: 'test@example.com', name: 'Test' })
expect(response.status).toBe(400)
})
})
测试内容:
最佳实践:
示例:
// Good: Tests complete user flow
describe('User Signup Flow', () => {
it('allows new user to signup and access dashboard', async () => {
await page.goto('/signup')
await page.fill('input[name="email"]', 'newuser@example.com')
await page.fill('input[name="password"]', 'SecurePass123!')
await page.click('button[type="submit"]')
await page.waitForURL('/dashboard')
expect(await page.textContent('h1')).toContain('Welcome')
})
})
JavaScript/TypeScript:
Python:
通用:
1. 可读性
2. 可维护性
3. 测试
4. 安全性
代码审查前:
关注点:
关键问题 (必须修复):
重要问题 (应该修复):
次要问题 (最好修复):
评分系统 (0-100):
安全性 (30 分):
可读性 (25 分):
测试 (25 分):
可维护性 (20 分):
等级:
验证门确保每个阶段在进入下一阶段前都已完成。
门标准:
可交付成果:
审查问题:
门标准:
可交付成果:
审查问题:
门标准:
可交付成果:
审查问题:
门标准:
可交付成果:
审查问题:
项目: 用户管理的 REST API
测试计划:
单元测试 (70%):
集成测试 (20%):
端到端测试 (10%):
工具:
覆盖率目标: 整体 90%
之前 (质量差 - 评分:55/100):
// Bad: Hardcoded secret, no error handling, poor naming
function getData(x) {
const result = fetch('https://api.example.com/data', {
headers: { Authorization: 'Bearer sk_live_abc123' }
})
return result.json()
}
问题:
之后 (质量好 - 评分:95/100):
// Good: Secure, robust, clear
async function fetchUserData(userId: string): Promise<UserData> {
try {
const apiKey = process.env.API_KEY;
if (!apiKey) {
throw new Error('API_KEY environment variable not set');
}
const response = await fetch(`https://api.example.com/users/${userId}`, {
headers: { 'Authorization': `Bearer ${apiKey}` }
});
if (!response.ok) {
throw new Error(`API request failed: ${response.status}`);
}
return await response.json();
} catch (error) {
logger.error('Failed to fetch user data', { userId, error });
throw new Error(`Failed to fetch user ${userId}`);
}
}
// Tests
describe('fetchUserData', () => {
it('fetches user successfully', async () => {
// Test implementation
});
it('throws error if API_KEY not set', async () => {
// Test implementation
});
});
项目: 客户支持聊天机器人 (阶段 3 → 阶段 4)
验证检查:
要求:
决定: 门失败 - 必须在继续之前修复 SAST 问题
行动项:
预计通过时间: 2 天
反模式: 测试实现细节 (私有方法) 更好: 测试公共 API 和行为
反模式: 只测试成功路径 更好: 测试空值、空数组、错误、边界
反模式: "我们发布后再修复" 结果: 生产环境错误、安全问题
更好: 强制执行门,必要时延迟
反模式: 对所有内容追求 100% 覆盖率,完美主义瘫痪 更好: 与风险相匹配的务实质量
反模式: 记得在提交前运行 linter 更好: 在预提交钩子和 CI/CD 中自动化
使用质量保证时,产出:
测试策略文档
代码质量标准
阶段门标准
质量仪表板
质量保证有效时:
记住: 质量不是可选的。它是可持续软件和技术破产之间的区别。
每周安装
0
仓库
GitHub 星标
18
首次出现
Jan 1, 1970
安全审计
Quality Assurance is a consolidated skill that combines three critical quality dimensions: comprehensive testing strategy, code quality enforcement, and phase-gate validation. It ensures your code is tested, maintainable, and ready for production at every stage.
Consolidated from:
Use Quality Assurance when:
Structure:
/\
/E2E\ 10% - End-to-End (Critical user flows)
/------\
/Integr-\ 20% - Integration (Components, APIs, DB)
/----------\
/ Unit \ 70% - Unit (Functions, classes, logic)
/--------------\
Rationale:
Coverage Targets:
What to Test:
Best Practices:
Example:
// Good: Fast, isolated, clear
describe('calculateDiscount', () => {
it('applies 10% discount for orders over $100', () => {
const result = calculateDiscount(150)
expect(result).toBe(15)
})
it('returns 0 for orders under $100', () => {
const result = calculateDiscount(50)
expect(result).toBe(0)
})
it('throws error for negative amounts', () => {
expect(() => calculateDiscount(-10)).toThrow()
})
})
What to Test:
Best Practices:
Example:
// Good: Real database, tests integration
describe('POST /api/users', () => {
beforeEach(async () => {
await db.users.deleteMany({})
})
it('creates user and returns 201', async () => {
const response = await request(app)
.post('/api/users')
.send({ email: 'test@example.com', name: 'Test' })
expect(response.status).toBe(201)
expect(response.body.email).toBe('test@example.com')
const user = await db.users.findOne({ email: 'test@example.com' })
expect(user).toBeDefined()
})
it('returns 400 for duplicate email', async () => {
await db.users.create({ email: 'test@example.com' })
const response = await request(app)
.post('/api/users')
.send({ email: 'test@example.com', name: 'Test' })
expect(response.status).toBe(400)
})
})
What to Test:
Best Practices:
Example:
// Good: Tests complete user flow
describe('User Signup Flow', () => {
it('allows new user to signup and access dashboard', async () => {
await page.goto('/signup')
await page.fill('input[name="email"]', 'newuser@example.com')
await page.fill('input[name="password"]', 'SecurePass123!')
await page.click('button[type="submit"]')
await page.waitForURL('/dashboard')
expect(await page.textContent('h1')).toContain('Welcome')
})
})
JavaScript/TypeScript:
Python:
General:
1. Readability
2. Maintainability
3. Testing
4. Security
Before Code Review:
What to Look For:
Critical Issues (Must Fix):
Important Issues (Should Fix):
Minor Issues (Nice to Fix):
Scoring System (0-100):
Security (30 points):
Readability (25 points):
Testing (25 points):
Maintainability (20 points):
Grading:
Validation gates ensure each phase is complete before moving to the next.
Gate Criteria:
Deliverables:
Review Questions:
Gate Criteria:
Deliverables:
Review Questions:
Gate Criteria:
Deliverables:
Review Questions:
Gate Criteria:
Deliverables:
Review Questions:
Project: REST API for user management
Test Plan:
Unit Tests (70%):
Integration Tests (20%):
E2E Tests (10%):
Tools:
Coverage Target: 90% overall
Before (Poor Quality - Score: 55/100):
// Bad: Hardcoded secret, no error handling, poor naming
function getData(x) {
const result = fetch('https://api.example.com/data', {
headers: { Authorization: 'Bearer sk_live_abc123' }
})
return result.json()
}
Issues:
After (Good Quality - Score: 95/100):
// Good: Secure, robust, clear
async function fetchUserData(userId: string): Promise<UserData> {
try {
const apiKey = process.env.API_KEY;
if (!apiKey) {
throw new Error('API_KEY environment variable not set');
}
const response = await fetch(`https://api.example.com/users/${userId}`, {
headers: { 'Authorization': `Bearer ${apiKey}` }
});
if (!response.ok) {
throw new Error(`API request failed: ${response.status}`);
}
return await response.json();
} catch (error) {
logger.error('Failed to fetch user data', { userId, error });
throw new Error(`Failed to fetch user ${userId}`);
}
}
// Tests
describe('fetchUserData', () => {
it('fetches user successfully', async () => {
// Test implementation
});
it('throws error if API_KEY not set', async () => {
// Test implementation
});
});
Project: Customer Support Chatbot (Phase 3 → Phase 4)
Validation Check:
Requirements:
Decision: GATE FAILED - Must fix SAST issues before proceeding
Action Items:
Estimated Time to Pass: 2 days
Antipattern: Test implementation details (private methods) Better: Test public API and behavior
Antipattern: Only test happy path Better: Test nulls, empty arrays, errors, boundaries
Antipattern: "We'll fix it after shipping" Result: Production bugs, security issues
Better: Enforce gates, delay if needed
Antipattern: 100% coverage on everything, perfection paralysis Better: Pragmatic quality aligned with risk
Antipattern: Remember to run linter before commit Better: Automate in pre-commit hooks + CI/CD
When using Quality Assurance, produce:
Test Strategy Document
Code Quality Standards
Phase Gate Criteria
Quality Dashboard
Quality Assurance is working when:
Remember: Quality is not optional. It's the difference between sustainable software and technical bankruptcy.
Weekly Installs
0
Repository
GitHub Stars
18
First Seen
Jan 1, 1970
Security Audits
测试策略完整指南:单元/集成/E2E测试金字塔与自动化实践
11,200 周安装