Loading...
Loading...
Compare original and translation side by side
.coverage.coverageUser: Analyze test coverage gaps in my src/ directory
Claude:
1. Scans src/ for all Python files
2. Reads .coverage or uses ast analysis
3. Identifies untested functions
4. Generates gap report with suggestions
Output:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Test Gap Analysis Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Summary:
- Total functions: 145
- Untested: 23 (16%)
- Low coverage (< 85%): 34 (23%)
CRITICAL GAPS (High Risk):
1. payment_processor.py::process_payment()
- Untested | Handles money | 15 min effort
- Suggested tests:
- Valid payment processing
- Insufficient funds error
- Payment timeout
- Currency conversion
MEDIUM GAPS:
2. user_service.py::validate_email()
- 40% coverage | Missing edge cases
- Suggested tests:
- Unicode characters
- Long email addresses
- Special characters
LOW GAPS:
3. utils.py::format_date()
- 60% coverage
- Suggested tests:
- Timezone handling
- Daylight saving transitions用户:分析我src/目录下的测试覆盖率缺口
Claude:
1. 扫描src/下的所有Python文件
2. 读取.coverage文件或使用AST分析
3. 识别未测试的函数
4. 生成带建议的缺口报告
输出:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
测试缺口分析报告
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
摘要:
- 总函数数:145
- 未测试:23个(16%)
- 低覆盖率(<85%):34个(23%)
关键缺口(高风险):
1. payment_processor.py::process_payment()
- 未测试 | 处理资金 | 15分钟工作量
- 建议测试:
- 有效支付处理
- 资金不足错误
- 支付超时
- 货币转换
中等缺口:
2. user_service.py::validate_email()
- 40%覆盖率 | 缺失边缘情况
- 建议测试:
- Unicode字符
- 长邮箱地址
- 特殊字符
低优先级缺口:
3. utils.py::format_date()
- 60%覆盖率
- 建议测试:
- 时区处理
- 夏令时转换User: Generate test templates for my untested auth module
Claude:
Creates templates organized by testing pyramid:
Unit Tests (60%):
- test_token_validation_valid()
- test_token_validation_expired()
- test_token_validation_invalid_signature()
Integration Tests (30%):
- test_auth_flow_with_database()
- test_multi_user_concurrent_auth()
E2E Tests (10%):
- test_user_login_to_protected_resource()
- test_session_persistence_across_requests()用户:为我未测试的auth模块生成测试模板
Claude:
按测试金字塔组织生成模板:
单元测试(60%):
- test_token_validation_valid()
- test_token_validation_expired()
- test_token_validation_invalid_signature()
集成测试(30%):
- test_auth_flow_with_database()
- test_multi_user_concurrent_auth()
E2E测试(10%):
- test_user_login_to_protected_resource()
- test_session_persistence_across_requests()User: Help me improve test coverage from 65% to 85%
Claude:
1. Analyzes current coverage
2. Identifies gaps blocking 85% threshold
3. Prioritizes by impact
4. Estimates effort
Output:
To reach 85% coverage:
- 12 quick wins (< 2 hours each)
- 3 medium tasks (2-4 hours each)
- 2 complex tasks (4+ hours each)
Recommended order:
1. Add error case tests (5 tests, 3 hours) -> +8%
2. Cover auth edge cases (8 tests, 4 hours) -> +6%
3. Add integration tests (12 tests, 6 hours) -> +7%用户:帮我将测试覆盖率从65%提升到85%
Claude:
1. 分析当前覆盖率
2. 识别阻碍达到85%阈值的缺口
3. 按影响优先级排序
4. 估算工作量
输出:
要达到85%覆盖率:
- 12个快速任务(每个<2小时)
- 3个中等任务(2-4小时)
- 2个复杂任务(4+小时)
推荐顺序:
1. 添加错误用例测试(5个测试,3小时)→ +8%
2. 覆盖auth边缘情况(8个测试,4小时)→ +6%
3. 添加集成测试(12个测试,6小时)→ +7%undefinedundefinedundefinedundefineddef test_function_name_happy_path():
"""Test function with valid inputs."""
# Arrange
input_data = {...}
expected = {...}
# Act
result = function_name(input_data)
# Assert
assert result == expecteddef test_function_name_happy_path():
"""测试函数的正常输入场景。"""
# 准备
input_data = {...}
expected = {...}
# 执行
result = function_name(input_data)
# 断言
assert result == expecteddef test_function_name_invalid_input():
"""Test function raises ValueError on invalid input."""
with pytest.raises(ValueError, match="Expected error message"):
function_name(invalid_input)def test_function_name_invalid_input():
"""测试函数在输入无效时抛出ValueError。"""
with pytest.raises(ValueError, match="预期错误信息"):
function_name(invalid_input)def test_function_name_edge_case():
"""Test function handles edge case correctly."""
# Test boundary conditions
result = function_name(boundary_value)
assert result is not Nonedef test_function_name_edge_case():
"""测试函数正确处理边缘情况。"""
# 测试边界条件
result = function_name(boundary_value)
assert result is not Nonedef test_user_service_with_database(test_db):
"""Test user service with real database."""
user_service = UserService(test_db)
user = user_service.create_user("test@example.com")
assert user.id is not Nonedef test_user_service_with_database(test_db):
"""测试用户服务与真实数据库的集成。"""
user_service = UserService(test_db)
user = user_service.create_user("test@example.com")
assert user.id is not NoneUser: Quick test coverage review of api/
Claude:
- Scans directory
- Identifies top 5 gaps
- Provides quick recommendations
- Total time: < 2 minutes用户:快速评审api/目录的测试覆盖率
Claude:
- 扫描目录
- 识别前5个缺口
- 提供快速建议
- 总耗时:<2分钟User: Plan test coverage improvement from 60% to 85%
Claude:
- Analyzes gaps
- Creates phased improvement plan
- Prioritizes by risk
- Provides effort estimates
- Generates all test templates用户:规划将测试覆盖率从60%提升到85%
Claude:
- 分析缺口
- 创建分阶段提升计划
- 按风险优先级排序
- 提供工作量估算
- 生成所有测试模板User: Generate complete test plan for new auth module
Claude:
- Analyzes module structure
- Maps public functions
- Creates test suggestions
- Balances testing pyramid
- Provides all templates用户:为新的auth模块生成完整测试计划
Claude:
- 分析模块结构
- 映射公共函数
- 创建测试建议
- 平衡测试金字塔
- 提供所有模板undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedProject Stats:
- 156 functions
- 52% test coverage
- Unknown untested functions
- Scattered test files项目统计:
- 156个函数
- 52%测试覆盖率
- 未知的未测试函数
- 分散的测试文件Gap Report:
- 24 untested functions (15%)
- 34 functions < 85% (22%)
- 12 critical gaps (high impact)
- 45 medium gaps (medium impact)
- 40 low gaps (low priority)
Recommendations:
1. Focus on critical gaps (payment, auth, data)
2. Add error case tests (20 tests, 8 hours)
3. Cover edge cases (15 tests, 6 hours)
4. Integration tests (12 tests, 10 hours)
Result after implementing:
- 89% test coverage
- All critical functions tested
- Balanced testing pyramid
- Improved confidence in refactoring缺口报告:
- 24个未测试函数(15%)
- 34个覆盖率<85%的函数(22%)
- 12个关键缺口(高影响)
- 45个中等缺口(中影响)
- 40个低优先级缺口(低影响)
建议:
1. 聚焦关键缺口(支付、认证、数据相关)
2. 添加错误用例测试(20个测试,8小时)
3. 覆盖边缘情况(15个测试,6小时)
4. 集成测试(12个测试,10小时)
实施后结果:
- 89%测试覆盖率
- 所有关键函数均已测试
- 测试金字塔均衡
- 重构信心提升