sonar_get_uncovered_files
Get list of files with coverage below target threshold. Returns prioritized list of files needing test coverage.
Description
Identifies files that need more test coverage by analyzing SonarQube coverage data. Files are prioritized based on coverage percentage (critical/high/medium/low) to help focus testing efforts on the most impactful areas.
Handles projects without coverage data by providing setup instructions.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
targetCoverage | number | No | 100 | Target coverage percentage (0-100). Files below this threshold are returned |
maxFiles | number | No | 50 | Maximum number of files to return (1-500) |
sortBy | string | No | coverage | Sort order: coverage (lowest first), uncovered_lines (most first), name (alphabetical) |
includeNoCoverageData | boolean | No | false | Include files without coverage data |
Priority Levels
Files are categorized by coverage percentage:
| Priority | Coverage | Description |
|---|---|---|
| Critical | 0-25% | Severe lack of testing |
| High | 26-50% | Significant coverage gaps |
| Medium | 51-75% | Moderate coverage |
| Low | 76-99% | Near target coverage |
Usage
Basic Usage
Show me files that need more test coverage
Tool call:
{
}
Custom Target
Show me files with less than 80% coverage
Tool call:
{
"targetCoverage": 80
}
Focus on Worst Files
Show me the 10 files with least coverage
Tool call:
{
"maxFiles": 10,
"sortBy": "coverage"
}
Sort by Impact
Which files have the most uncovered lines?
Tool call:
{
"sortBy": "uncovered_lines",
"maxFiles": 20
}
Response Format
UNCOVERED FILES ANALYSIS
━━━━━━━━━━━━━━━━━━━━━━━━
Target Coverage: 80%
Files Below Target: 23
📊 PRIORITY BREAKDOWN:
🔴 Critical (0-25%): 3 files
🟠 High (26-50%): 7 files
🟡 Medium (51-75%): 8 files
🟢 Low (76-79%): 5 files
FILES NEEDING COVERAGE:
🔴 CRITICAL PRIORITY
1. src/services/PaymentService.ts
Coverage: 12.5%
Uncovered Lines: 145
Component Key: my-project:src/services/PaymentService.ts
2. src/utils/crypto.ts
Coverage: 18.2%
Uncovered Lines: 89
Component Key: my-project:src/utils/crypto.ts
3. src/api/handlers/webhooks.ts
Coverage: 23.1%
Uncovered Lines: 67
Component Key: my-project:src/api/handlers/webhooks.ts
🟠 HIGH PRIORITY
4. src/services/UserService.ts
Coverage: 34.7%
Uncovered Lines: 112
Component Key: my-project:src/services/UserService.ts
5. src/middleware/auth.ts
Coverage: 41.2%
Uncovered Lines: 58
Component Key: my-project:src/middleware/auth.ts
...
SUMMARY:
Total uncovered lines: 1,247
Estimated tests needed: 50-75
Potential coverage increase: +35%
💡 RECOMMENDATIONS:
• Start with Critical files for maximum impact
• Use sonar_get_coverage_gaps for detailed analysis
• Focus on business-critical paths first
Examples
Example 1: Coverage Sprint Planning
Prompt:
I need to improve test coverage. Show me where to start.
Tool Call:
{
"targetCoverage": 80,
"maxFiles": 15,
"sortBy": "uncovered_lines"
}
Example 2: Find Zero Coverage Files
Prompt:
Are there any files with no tests at all?
Tool Call:
{
"targetCoverage": 1,
"sortBy": "coverage"
}
Example 3: Incremental Improvement
Prompt:
Show me files that are close to 80% coverage
Tool Call:
{
"targetCoverage": 80,
"sortBy": "coverage",
"maxFiles": 10
}
Files closest to threshold will appear last (sorted by lowest coverage first).
Example 4: Include Unscanned Files
Prompt:
Show me all files that might need coverage, including ones never scanned
Tool Call:
{
"includeNoCoverageData": true,
"maxFiles": 100
}
No Coverage Data
If your project has never been scanned with coverage reports:
NO COVERAGE DATA AVAILABLE
━━━━━━━━━━━━━━━━━━━━━━━━━━
This project has no coverage data in SonarQube.
To enable coverage analysis:
1. Configure your test framework to generate coverage reports
2. Set the coverage report path in sonar-project.properties:
# For JavaScript/TypeScript (lcov)
sonar.javascript.lcov.reportPaths=coverage/lcov.info
# For Java (JaCoCo)
sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
# For Python (coverage.py)
sonar.python.coverage.reportPaths=coverage.xml
3. Re-run the scan with autoSetup: false
Workflow: Improving Coverage
1. sonar_get_uncovered_files (identify targets)
↓
2. sonar_get_coverage_gaps for top files (understand gaps)
↓
3. Write tests for uncovered code
↓
4. sonar_scan_project (verify improvement)
↓
5. Repeat until target coverage reached
Best Practices
- Prioritize by business impact - Critical services first
- Sort by uncovered_lines - Maximum coverage gain per test
- Set realistic targets - 80% is often a good balance
- Track progress - Re-run after adding tests
Common Issues
"No coverage data"
Cause: Coverage reports not configured or not generated.
Solution: Configure your test framework to generate coverage reports (lcov, JaCoCo, coverage.py).
"Zero files returned"
Cause: All files meet the target coverage.
Solution: Lower the targetCoverage threshold or your coverage is excellent!
"Files missing from results"
Cause: Files excluded from analysis or not compiled.
Solution: Check sonar.exclusions and ensure files are part of the build.
Related Tools
sonar_get_coverage_gaps- Detailed gaps per filesonar_get_project_metrics- Overall coveragesonar_scan_project- Run analysis with coverage