重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
coverage-strategist by patricio0312rev/skills
npx skills add https://github.com/patricio0312rev/skills --skill coverage-strategist定义务实、以投资回报率为导向的测试覆盖率策略。
目标:以最少的测试获得最大的信心
原则:100%覆盖率不是目标。测试重要的内容。
// Critical paths that MUST be tested
const criticalPaths = {
authentication: {
priority: "P0",
coverage: "100%",
paths: [
"User login flow",
"User registration",
"Password reset",
"Token refresh",
"Session management",
],
reasoning: "Security critical, impacts all users",
},
checkout: {
priority: "P0",
coverage: "100%",
paths: [
"Add to cart",
"Update cart",
"Apply coupon",
"Process payment",
"Order confirmation",
],
reasoning: "Revenue critical, business essential",
},
dataIntegrity: {
priority: "P0",
coverage: "100%",
paths: [
"User data CRUD",
"Order creation",
"Inventory updates",
"Database transactions",
],
reasoning: "Data corruption would be catastrophic",
},
};
// Important but not critical
const importantPaths = {
userProfile: {
priority: "P1",
coverage: "80%",
paths: ["Profile updates", "Avatar upload", "Preferences"],
reasoning: "Important UX, but not business critical",
},
search: {
priority: "P1",
coverage: "70%",
paths: ["Product search", "Filters", "Sorting"],
reasoning: "Enhances experience, not essential",
},
};
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# Coverage Targets by Layer
## 业务逻辑 / 核心功能:90-100%
**原因**:高投资回报率 - 复杂逻辑,众多边界情况
**测试内容**:
- 计算
- 验证
- 状态机
- 算法
- 数据转换
## API 端点:80-90%
**原因**:关键集成点
**测试内容**:
- 正常路径
- 错误情况
- 验证
- 认证
- 授权
## 数据库层:70-80%
**原因**:数据完整性很重要
**测试内容**:
- CRUD 操作
- 事务
- 约束
- 迁移
## UI 组件:50-70%
**原因**:投资回报率较低 - 视觉变化,不太关键
**测试内容**:
- 用户交互
- 状态变化
- 错误状态
- 仅关键流程
## 工具/辅助函数:80-90%
**原因**:各处复用,影响大
**测试内容**:
- 所有公共函数
- 边界情况
- 错误处理
// Explicit list of what NOT to test
const dontTestThese = {
externalLibraries: {
examples: ["React internals", "Next.js router", "Lodash functions"],
reasoning: "Already tested by library authors",
},
trivialCode: {
examples: [
"Simple getters/setters",
"Constants",
"Type definitions",
"Pass-through functions",
],
reasoning: "No logic to test, waste of time",
},
presentationalComponents: {
examples: ["Simple buttons", "Icons", "Layout wrappers"],
reasoning: "Visual regression testing more appropriate",
},
configurationFiles: {
examples: ["webpack.config.js", "next.config.js"],
reasoning: "Configuration, not logic",
},
mockData: {
examples: ["Fixtures", "Test data", "Storybook stories"],
reasoning: "Not production code",
},
};
// Example: Don't test trivial code
// ❌ Don't test this
class User {
constructor(private name: string) {}
getName() {
return this.name;
} // Trivial getter
}
// ✅ But DO test this
class User {
constructor(private name: string) {}
getDisplayName() {
// Business logic
return this.name
.split(" ")
.map((n) => n.charAt(0).toUpperCase() + n.slice(1))
.join(" ");
}
}
interface TestPriority {
feature: string;
businessImpact: "high" | "medium" | "low";
complexity: "high" | "medium" | "low";
changeFrequency: "high" | "medium" | "low";
priority: "P0" | "P1" | "P2" | "P3";
targetCoverage: string;
}
const testPriorities: TestPriority[] = [
{
feature: "Payment processing",
businessImpact: "high",
complexity: "high",
changeFrequency: "low",
priority: "P0",
targetCoverage: "100%",
},
{
feature: "User authentication",
businessImpact: "high",
complexity: "medium",
changeFrequency: "low",
priority: "P0",
targetCoverage: "100%",
},
{
feature: "Product search",
businessImpact: "medium",
complexity: "medium",
changeFrequency: "medium",
priority: "P1",
targetCoverage: "80%",
},
{
feature: "UI themes",
businessImpact: "low",
complexity: "low",
changeFrequency: "high",
priority: "P3",
targetCoverage: "30%",
},
];
// Priority calculation
function calculatePriority(
businessImpact: number, // 1-10
complexity: number, // 1-10
changeFrequency: number // 1-10
): number {
return businessImpact * 0.5 + complexity * 0.3 + changeFrequency * 0.2;
}
// jest.config.js
module.exports = {
collectCoverageFrom: [
"src/**/*.{ts,tsx}",
"!src/**/*.d.ts",
"!src/**/*.stories.tsx", // Don't count stories
"!src/mocks/**", // Don't count mocks
"!src/**/__tests__/**", // Don't count tests
],
coverageThresholds: {
global: {
statements: 70,
branches: 65,
functions: 70,
lines: 70,
},
// Critical paths: 90%+
"./src/services/payment/**/*.ts": {
statements: 90,
branches: 85,
functions: 90,
lines: 90,
},
"./src/services/auth/**/*.ts": {
statements: 90,
branches: 85,
functions: 90,
lines: 90,
},
// Utils: 80%+
"./src/utils/**/*.ts": {
statements: 80,
branches: 75,
functions: 80,
lines: 80,
},
// UI components: 50%+ (lower bar)
"./src/components/**/*.tsx": {
statements: 50,
branches: 45,
functions: 50,
lines: 50,
},
},
};
// Calculate ROI of testing
interface TestROI {
feature: string;
testingCost: number; // hours
bugPreventionValue: number; // estimated $ saved
roi: number; // ratio
}
const testROI: TestROI[] = [
{
feature: "Payment processing",
testingCost: 40, // hours
bugPreventionValue: 50000, // Could lose $50k revenue
roi: 1250, // $1,250 per hour invested
},
{
feature: "Authentication",
testingCost: 20,
bugPreventionValue: 10000, // Security breach cost
roi: 500,
},
{
feature: "Theme switcher",
testingCost: 5,
bugPreventionValue: 100, // Minor UX issue
roi: 20,
},
];
// Focus on high ROI tests
const sortedByROI = testROI.sort((a, b) => b.roi - a.roi);
# Testing Strategy Document
## 原则
1. **业务价值优先**:测试可能破坏业务的内容
2. **边界情况优于正常路径**:正常路径显而易见
3. **集成测试优于单元测试**:测试行为,而非实现
4. **关键流程端到端**:用户旅程最重要
## 测试类型分布
- 70% 单元测试(快速、隔离)
- 20% 集成测试(API + 数据库)
- 10% 端到端测试(仅关键流程)
## 覆盖率目标
- 总体:70%(务实目标)
- 关键业务逻辑:90%以上
- API 端点:80%以上
- UI 组件:50%以上(仅用户交互)
## 无需测试的内容
- 第三方库
- 简单的 getter/setter
- 纯展示型组件
- 配置文件
- 模拟数据和固定数据
## 评审标准
编写测试前,请自问:
1. 这个测试能防止什么错误?
2. 该错误发生的可能性有多大?
3. 该错误的成本有多高?
4. 集成测试是否已覆盖此内容?
如果投资回报率低,则跳过该测试。
// Code review checklist for test coverage
const reviewChecklist = {
criticalPath: {
question: "Does this change affect a critical path?",
ifYes: "MUST have comprehensive tests (90%+)",
},
businessLogic: {
question: "Is this complex business logic?",
ifYes: "MUST have unit tests with edge cases",
},
apiEndpoint: {
question: "Is this a new API endpoint?",
ifYes: "MUST have integration tests",
},
uiComponent: {
question: "Is this a UI component?",
ifYes: "Optional - test interactions only",
},
bugFix: {
question: "Is this a bug fix?",
ifYes: "MUST have regression test",
},
};
每周安装量
45
代码仓库
GitHub 星标数
23
首次出现
2026年1月24日
安全审计
安装于
claude-code37
codex36
gemini-cli36
opencode36
antigravity35
github-copilot35
Define pragmatic, ROI-focused test coverage strategies.
Goal : Maximum confidence with minimum tests
Principle : 100% coverage is not the goal. Test what matters.
// Critical paths that MUST be tested
const criticalPaths = {
authentication: {
priority: "P0",
coverage: "100%",
paths: [
"User login flow",
"User registration",
"Password reset",
"Token refresh",
"Session management",
],
reasoning: "Security critical, impacts all users",
},
checkout: {
priority: "P0",
coverage: "100%",
paths: [
"Add to cart",
"Update cart",
"Apply coupon",
"Process payment",
"Order confirmation",
],
reasoning: "Revenue critical, business essential",
},
dataIntegrity: {
priority: "P0",
coverage: "100%",
paths: [
"User data CRUD",
"Order creation",
"Inventory updates",
"Database transactions",
],
reasoning: "Data corruption would be catastrophic",
},
};
// Important but not critical
const importantPaths = {
userProfile: {
priority: "P1",
coverage: "80%",
paths: ["Profile updates", "Avatar upload", "Preferences"],
reasoning: "Important UX, but not business critical",
},
search: {
priority: "P1",
coverage: "70%",
paths: ["Product search", "Filters", "Sorting"],
reasoning: "Enhances experience, not essential",
},
};
# Coverage Targets by Layer
## Business Logic / Core Functions: 90-100%
**Why**: High ROI - complex logic, many edge cases
**What to test**:
- Calculations
- Validations
- State machines
- Algorithms
- Data transformations
## API Endpoints: 80-90%
**Why**: Critical integration points
**What to test**:
- Happy paths
- Error cases
- Validation
- Authentication
- Authorization
## Database Layer: 70-80%
**Why**: Data integrity matters
**What to test**:
- CRUD operations
- Transactions
- Constraints
- Migrations
## UI Components: 50-70%
**Why**: Lower ROI - visual changes, less critical
**What to test**:
- User interactions
- State changes
- Error states
- Critical flows only
## Utils/Helpers: 80-90%
**Why**: Reused everywhere, high impact
**What to test**:
- All public functions
- Edge cases
- Error handling
// Explicit list of what NOT to test
const dontTestThese = {
externalLibraries: {
examples: ["React internals", "Next.js router", "Lodash functions"],
reasoning: "Already tested by library authors",
},
trivialCode: {
examples: [
"Simple getters/setters",
"Constants",
"Type definitions",
"Pass-through functions",
],
reasoning: "No logic to test, waste of time",
},
presentationalComponents: {
examples: ["Simple buttons", "Icons", "Layout wrappers"],
reasoning: "Visual regression testing more appropriate",
},
configurationFiles: {
examples: ["webpack.config.js", "next.config.js"],
reasoning: "Configuration, not logic",
},
mockData: {
examples: ["Fixtures", "Test data", "Storybook stories"],
reasoning: "Not production code",
},
};
// Example: Don't test trivial code
// ❌ Don't test this
class User {
constructor(private name: string) {}
getName() {
return this.name;
} // Trivial getter
}
// ✅ But DO test this
class User {
constructor(private name: string) {}
getDisplayName() {
// Business logic
return this.name
.split(" ")
.map((n) => n.charAt(0).toUpperCase() + n.slice(1))
.join(" ");
}
}
interface TestPriority {
feature: string;
businessImpact: "high" | "medium" | "low";
complexity: "high" | "medium" | "low";
changeFrequency: "high" | "medium" | "low";
priority: "P0" | "P1" | "P2" | "P3";
targetCoverage: string;
}
const testPriorities: TestPriority[] = [
{
feature: "Payment processing",
businessImpact: "high",
complexity: "high",
changeFrequency: "low",
priority: "P0",
targetCoverage: "100%",
},
{
feature: "User authentication",
businessImpact: "high",
complexity: "medium",
changeFrequency: "low",
priority: "P0",
targetCoverage: "100%",
},
{
feature: "Product search",
businessImpact: "medium",
complexity: "medium",
changeFrequency: "medium",
priority: "P1",
targetCoverage: "80%",
},
{
feature: "UI themes",
businessImpact: "low",
complexity: "low",
changeFrequency: "high",
priority: "P3",
targetCoverage: "30%",
},
];
// Priority calculation
function calculatePriority(
businessImpact: number, // 1-10
complexity: number, // 1-10
changeFrequency: number // 1-10
): number {
return businessImpact * 0.5 + complexity * 0.3 + changeFrequency * 0.2;
}
// jest.config.js
module.exports = {
collectCoverageFrom: [
"src/**/*.{ts,tsx}",
"!src/**/*.d.ts",
"!src/**/*.stories.tsx", // Don't count stories
"!src/mocks/**", // Don't count mocks
"!src/**/__tests__/**", // Don't count tests
],
coverageThresholds: {
global: {
statements: 70,
branches: 65,
functions: 70,
lines: 70,
},
// Critical paths: 90%+
"./src/services/payment/**/*.ts": {
statements: 90,
branches: 85,
functions: 90,
lines: 90,
},
"./src/services/auth/**/*.ts": {
statements: 90,
branches: 85,
functions: 90,
lines: 90,
},
// Utils: 80%+
"./src/utils/**/*.ts": {
statements: 80,
branches: 75,
functions: 80,
lines: 80,
},
// UI components: 50%+ (lower bar)
"./src/components/**/*.tsx": {
statements: 50,
branches: 45,
functions: 50,
lines: 50,
},
},
};
// Calculate ROI of testing
interface TestROI {
feature: string;
testingCost: number; // hours
bugPreventionValue: number; // estimated $ saved
roi: number; // ratio
}
const testROI: TestROI[] = [
{
feature: "Payment processing",
testingCost: 40, // hours
bugPreventionValue: 50000, // Could lose $50k revenue
roi: 1250, // $1,250 per hour invested
},
{
feature: "Authentication",
testingCost: 20,
bugPreventionValue: 10000, // Security breach cost
roi: 500,
},
{
feature: "Theme switcher",
testingCost: 5,
bugPreventionValue: 100, // Minor UX issue
roi: 20,
},
];
// Focus on high ROI tests
const sortedByROI = testROI.sort((a, b) => b.roi - a.roi);
# Testing Strategy Document
## Principles
1. **Business value first**: Test what breaks the business
2. **Edge cases over happy path**: Happy path is obvious
3. **Integration over unit**: Test how pieces work together
4. **Critical flows end-to-end**: User journeys matter most
## Test Types Distribution
- 70% Unit tests (fast, isolated)
- 20% Integration tests (API + DB)
- 10% E2E tests (critical flows only)
## Coverage Goals
- Overall: 70% (pragmatic goal)
- Critical business logic: 90%+
- API endpoints: 80%+
- UI components: 50%+ (user interactions only)
## What NOT to Test
- Third-party libraries
- Trivial getters/setters
- Pure presentational components
- Configuration files
- Mock data and fixtures
## Review Criteria
Before writing a test, ask:
1. What bug would this test prevent?
2. How likely is that bug?
3. How costly would that bug be?
4. Is this already covered by integration tests?
If ROI is low, skip the test.
// Code review checklist for test coverage
const reviewChecklist = {
criticalPath: {
question: "Does this change affect a critical path?",
ifYes: "MUST have comprehensive tests (90%+)",
},
businessLogic: {
question: "Is this complex business logic?",
ifYes: "MUST have unit tests with edge cases",
},
apiEndpoint: {
question: "Is this a new API endpoint?",
ifYes: "MUST have integration tests",
},
uiComponent: {
question: "Is this a UI component?",
ifYes: "Optional - test interactions only",
},
bugFix: {
question: "Is this a bug fix?",
ifYes: "MUST have regression test",
},
};
Weekly Installs
45
Repository
GitHub Stars
23
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubFailSocketWarnSnykPass
Installed on
claude-code37
codex36
gemini-cli36
opencode36
antigravity35
github-copilot35
后端测试指南:API端点、业务逻辑与数据库测试最佳实践
11,800 周安装
LangChain4j AI 服务模式指南:Java声明式AI接口构建与内存管理
418 周安装
Xcode构建与导出指南:使用asc-xcode-build自动化iOS/macOS应用上传App Store
437 周安装
创业画布:新产品战略与商业模式规划工具 | 初创公司必备
425 周安装
邮件管理专家技能:高效处理Apple Mail收件箱,实现零收件箱工作流
421 周安装
JUnit 5 参数化单元测试指南:@ValueSource、@MethodSource、@CsvSource 详解与示例
419 周安装
本地代码变更审查指南 - 自动化代码质量与安全审计工具
424 周安装