Find Untested Sources
Purpose
Coverage tools answer "which lines were executed?" — they require a green build
and a passing test run, which is minutes-to-tens-of-minutes on a real repo. The
question this skill answers is different and much cheaper:
Which source files have no test file referencing any of their declared
types/symbols?
That's the question an agent asks before writing a new test — and it can be
answered statically in a few seconds by parsing source files, with no build,
no dependency resolution, and no compilation. The output is a deterministic
test-pairing map that lets the agent pick the next file to test without reading
the entire codebase first.
Two engines — pick one
This skill ships two interchangeable analyzers with a compatible JSON contract:
| Engine |
Script |
Use when |
| Roslyn (C#) |
scripts/Find-UntestedSources.cs |
The repo is .NET-only. Parses every .cs file with the Roslyn syntax API and does strict namespace disambiguation, so it is materially more accurate on duplicated short names like Settings or Context. |
| tree-sitter (polyglot) |
scripts/find_untested_sources.py |
The repo is not exclusively C#, or you want one tool across Python, TypeScript/JavaScript, Go, Java, Rust, Ruby, and C#. |
For a .NET-only repository, prefer the Roslyn engine — its namespace-aware
pairing beats the polyglot engine's identifier overlap.
When to Use
- User asks "where should I add tests?", "which files have no tests?", "find
untested code", "give me a test gap list", "what's the next file to test".
- Before invoking a test-generation agent, to produce a prioritized worklist.
- After generating tests, to verify each new test file pairs to a source file.
- To enumerate "weakly paired" source files (only one referring test) for
follow-up depth checks.
When Not to Use
- Line/branch coverage — use
coverage-analysis.
- CRAP-score / risk hotspots — use
coverage-analysis.
- Are existing tests strong? — use
test-gap-analysis (mutation reasoning)
or assertion-quality.
Roslyn engine (C#)
Prerequisites
- .NET SDK that supports file-based apps (
dotnet run script.cs). Pinned in the
repo's global.json (SDK 11 preview or later).
- No internet access required beyond the initial NuGet restore of
Microsoft.CodeAnalysis.CSharp on first run.
Usage
# From the skill folder
dotnet run scripts/Find-UntestedSources.cs -- <repo-root> [--top N]
# Save the report
dotnet run scripts/Find-UntestedSources.cs -- <repo-root> > pairing.json
# Iterate the untested list, highest-API-surface first
$report = Get-Content pairing.json | ConvertFrom-Json
$report.untested | Select-Object -First 10 source, decl_count, suggested_test_path
Diagnostics go to stderr; JSON goes to stdout.
Output schema
{
"repo": "<absolute path>",
"elapsed_ms": 8883,
"counts": {
"source_files": 3036,
"test_files": 867,
"untested_files": 1852,
"paired_files": 1184
},
"untested": [
{
"source": "src/Foo/Bar.cs",
"decl_count": 8, // # of type declarations in the file
"suggested_test_path": // mirror of source under a discovered test project
"tests/Foo.Tests/Bar/BarTests.cs"
}
],
"source_to_tests": {
"src/Foo/Baz.cs": [
"tests/Foo.Tests/BazTests.cs",
"tests/Foo.IntegrationTests/Scenarios/BazScenarios.cs"
]
}
}
How it works
- File discovery — recursive walk pruning
bin/, obj/, node_modules/,
.git/, .vs/, packages/, and any dotted subdir. Skips generated files
(.g.cs, .Designer.cs, .AssemblyInfo.cs).
- Test vs source classification — walks up to the nearest
.csproj and
marks it a test project if the project name ends in .Tests, .Test,
.UnitTests, .IntegrationTests, .E2E, .EndToEnd, .Spec, .Specs, or
the content references Microsoft.NET.Test.Sdk, MSTest.Sdk,
Microsoft.Testing.Platform, xunit, NUnit, TUnit, or
<IsTestProject>true</IsTestProject>.
- Source index (parallel) — parse each source file with
CSharpSyntaxTree.ParseText (syntax only, no compilation); record every
BaseTypeDeclarationSyntax / DelegateDeclarationSyntax as
(ShortName, EnclosingNamespace, FilePath).
- Test scan (parallel) — parse each test file, collect
using directives +
enclosing namespace, walk every IdentifierToken, look it up in the
short-name index, and disambiguate strictly: an identifier is attributed
only if the declaration's namespace matches one of the test file's using
directives, the enclosing namespace, or a prefix of them. This avoids noise
where common names like Settings or Context match every project.
- Pairing & suggestion — invert into
source → [tests]. Build a
production-to-test project map from <ProjectReference> entries; for each
untested source, mirror its in-project relative path under the referencing
test project to suggest a path.
- JSON emit — ordered by declaration count desc, then alphabetical.
Polyglot engine (tree-sitter)
Prerequisites
- Python 3.10+.
pip install tree-sitter-language-pack (single self-contained wheel that
bundles parsers for 300+ languages and the high-level process() API). No
native build, no per-language grammar install.
Usage
# From the skill folder
python scripts/find_untested_sources.py <repo-root>
# Restrict to a language (repeatable)
python scripts/find_untested_sources.py <repo-root> --lang python --lang typescript
# Truncate the report (top 20 by declared API surface)
python scripts/find_untested_sources.py <repo-root> --limit-untested 20 > pairing.json
# Iterate, highest-API-surface first
$report = Get-Content pairing.json | ConvertFrom-Json
$report.untested_sources | Select-Object -First 10 path, declaration_count, suggested_test_path
Pass --include-tested to additionally emit tested_sources (omitted by
default to keep the payload small for LLM consumption). Diagnostics go to
stderr; JSON goes to stdout.
Output schema
{
"repo_root": "<absolute path>",
"summary": {
"source_files": 3138,
"test_files": 761,
"tested_source_files": 1419,
"untested_source_files": 1719,
"orphan_test_files": 15,
"languages": ["csharp"]
},
"untested_sources": [
{
"path": "src/Foo/Bar.cs",
"language": "csharp",
"declaration_count": 8,
"declarations": ["Bar", "BarOptions", "IBar", "..."],
"suggested_test_path": "src/Foo/BarTests.cs"
}
],
"orphan_tests": [
{ "path": "tests/SomeIntegrationTest.cs", "language": "csharp" }
]
}
How it works
File discovery — recursive walk pruning common build/vendor dirs (bin,
obj, node_modules, target, dist, build, vendor, __pycache__,
.venv, .git, …) and generated files (.d.ts, .g.cs, .Designer.cs,
_pb2.py, *.min.js, AssemblyInfo.cs, …).
Language detection — detect_language_from_path maps the extension to a
supported language; unknown extensions are skipped.
Test-vs-source classification — per-language path heuristics:
| Language |
Test rule |
| Python |
path contains tests//test/; or filename starts with test_ or ends _test.py; or conftest.py. |
| JS/TS/TSX |
path contains __tests__, tests, test, spec, e2e; or filename contains .test./.spec.. |
| Go |
filename ends _test.go. |
| Java |
path contains test/tests; or filename ends Test.java/Tests.java. |
| Rust |
path contains tests//benches/. |
| C# |
path contains tests/; or project segment ends .Tests/.Test/.UnitTests/.IntegrationTests; or filename ends Tests/Test. |
| Ruby |
path contains spec//test/; or filename ends _spec.rb/_test.rb. |
Per-file extraction — process(text, ProcessConfig(structure, imports, symbols)) returns declared items, raw import statements, and a flat declared
-name list.
Pairing — for each test file, union import resolution (per language,
e.g. Python from pkg.mod import x → pkg/mod.py; Java import a.b.C; →
a/b/C.java; C# using is namespace-not-file, so a no-op) with identifier
overlap (word-like tokens, length ≥ 4, matched against declared names).
JSON emit — untested_sources ordered by declaration count descending.
Limitations (be honest with the agent)
Both engines are static, parse-only heuristics that trade a little accuracy for
orders-of-magnitude lower cost than coverage. Known gaps:
- Reflection / DI-resolved types referenced only via a string name or
container resolution won't be detected — the type's short name never appears
in the test source.
- Extension methods invoked as instance methods (C#): the declaring static
class is not named, so its file is not credited.
var, target-typed new(), pattern matching lose the type token; the
file-level union usually still catches it through other references.
- Short identifier names (polyglot, < 4 chars) are dropped to avoid noisy
pairings on names like
id, db, Tag.
- Monorepo path aliases (TS path mapping, Java module-info) are not
resolved; a suffix-match fallback may pick the wrong source if two files share
a trailing path segment.
For these cases, run actual coverage (coverage-analysis) on the unpaired
candidates the agent has already triaged.
Outputs the agent should consume
untested[*].source / untested_sources[*].path — pick the next source file
to test (highest declaration count first).
*.suggested_test_path — drop-in target for the new test file; the Roslyn
engine honors the test project that already <ProjectReference>s the source's
project, so dotnet sln add is not needed.
source_to_tests (Roslyn) / --include-tested tested_sources (polyglot) —
verify a newly written test file lands in the list for the intended source.
orphan_tests (polyglot) — tests that don't reference any same-language
source file; useful for triaging stale or integration-only tests.
1---2name: find-untested-sources3description: >4 Parse-only static analysis that pairs source files with the tests referencing5 them and emits JSON listing untested files ordered by API surface, each with a6 suggested_test_path. Roslyn engine for C#/.NET (namespace-aware), tree-sitter7 engine for polyglot repos (Python, TS/JS, Go, Java, Rust, Ruby).8 USE FOR: where to write tests next, which files have no tests, find untested9 code, build a source-to-test pairing map, prioritized test-gap worklist.10 DO NOT USE FOR: line/branch coverage or CRAP risk (use coverage-analysis);11 whether existing tests are strong (use test-gap-analysis or assertion-quality).12license: MIT13# Agent-orchestrated helper (invoked by name from code-testing-researcher and the14# code-testing pipeline); kept out of the model-facing skill menu so it does not15# consume the plugin's 15,000-char skill-menu budget or add routing noise that16# suppresses activation of the user-facing test skills. Still invocable by name.17disable-model-invocation: true18metadata:19 source: https://skillmd.com/skills/dotnet/find-untested-sources20---2122# Find Untested Sources2324## Purpose2526Coverage tools answer "which lines were executed?" — they require a green build27and a passing test run, which is minutes-to-tens-of-minutes on a real repo. The28question this skill answers is different and much cheaper:2930> _Which source files have no test file referencing any of their declared31> types/symbols?_3233That's the question an agent asks **before** writing a new test — and it can be34answered statically in a few seconds by parsing source files, with **no build,35no dependency resolution, and no compilation**. The output is a deterministic36test-pairing map that lets the agent pick the next file to test without reading37the entire codebase first.3839## Two engines — pick one4041This skill ships two interchangeable analyzers with a compatible JSON contract:4243| Engine | Script | Use when |44|--------|--------|----------|45| **Roslyn (C#)** | `scripts/Find-UntestedSources.cs` | The repo is **.NET-only**. Parses every `.cs` file with the Roslyn syntax API and does strict **namespace disambiguation**, so it is materially more accurate on duplicated short names like `Settings` or `Context`. |46| **tree-sitter (polyglot)** | `scripts/find_untested_sources.py` | The repo is **not exclusively C#**, or you want one tool across Python, TypeScript/JavaScript, Go, Java, Rust, Ruby, and C#. |4748For a .NET-only repository, **prefer the Roslyn engine** — its namespace-aware49pairing beats the polyglot engine's identifier overlap.5051## When to Use5253- User asks "where should I add tests?", "which files have no tests?", "find54 untested code", "give me a test gap list", "what's the next file to test".55- Before invoking a test-generation agent, to produce a prioritized worklist.56- After generating tests, to verify each new test file pairs to a source file.57- To enumerate "weakly paired" source files (only one referring test) for58 follow-up depth checks.5960## When Not to Use6162- **Line/branch coverage** — use `coverage-analysis`.63- **CRAP-score / risk hotspots** — use `coverage-analysis`.64- **Are existing tests strong?** — use `test-gap-analysis` (mutation reasoning)65 or `assertion-quality`.6667## Roslyn engine (C#)6869### Prerequisites7071- .NET SDK that supports file-based apps (`dotnet run script.cs`). Pinned in the72 repo's `global.json` (SDK 11 preview or later).73- No internet access required beyond the initial NuGet restore of74 `Microsoft.CodeAnalysis.CSharp` on first run.7576### Usage7778```powershell79# From the skill folder80dotnet run scripts/Find-UntestedSources.cs -- <repo-root> [--top N]8182# Save the report83dotnet run scripts/Find-UntestedSources.cs -- <repo-root> > pairing.json8485# Iterate the untested list, highest-API-surface first86$report = Get-Content pairing.json | ConvertFrom-Json87$report.untested | Select-Object -First 10 source, decl_count, suggested_test_path88```8990Diagnostics go to stderr; JSON goes to stdout.9192### Output schema9394```jsonc95{96 "repo": "<absolute path>",97 "elapsed_ms": 8883,98 "counts": {99 "source_files": 3036,100 "test_files": 867,101 "untested_files": 1852,102 "paired_files": 1184103 },104 "untested": [105 {106 "source": "src/Foo/Bar.cs",107 "decl_count": 8, // # of type declarations in the file108 "suggested_test_path": // mirror of source under a discovered test project109 "tests/Foo.Tests/Bar/BarTests.cs"110 }111 ],112 "source_to_tests": {113 "src/Foo/Baz.cs": [114 "tests/Foo.Tests/BazTests.cs",115 "tests/Foo.IntegrationTests/Scenarios/BazScenarios.cs"116 ]117 }118}119```120121### How it works1221231. **File discovery** — recursive walk pruning `bin/`, `obj/`, `node_modules/`,124 `.git/`, `.vs/`, `packages/`, and any dotted subdir. Skips generated files125 (`.g.cs`, `.Designer.cs`, `.AssemblyInfo.cs`).1262. **Test vs source classification** — walks up to the nearest `.csproj` and127 marks it a test project if the project name ends in `.Tests`, `.Test`,128 `.UnitTests`, `.IntegrationTests`, `.E2E`, `.EndToEnd`, `.Spec`, `.Specs`, or129 the content references `Microsoft.NET.Test.Sdk`, `MSTest.Sdk`,130 `Microsoft.Testing.Platform`, `xunit`, `NUnit`, `TUnit`, or131 `<IsTestProject>true</IsTestProject>`.1323. **Source index (parallel)** — parse each source file with133 `CSharpSyntaxTree.ParseText` (syntax only, no compilation); record every134 `BaseTypeDeclarationSyntax` / `DelegateDeclarationSyntax` as135 `(ShortName, EnclosingNamespace, FilePath)`.1364. **Test scan (parallel)** — parse each test file, collect `using` directives +137 enclosing namespace, walk every `IdentifierToken`, look it up in the138 short-name index, and **disambiguate strictly**: an identifier is attributed139 only if the declaration's namespace matches one of the test file's `using`140 directives, the enclosing namespace, or a prefix of them. This avoids noise141 where common names like `Settings` or `Context` match every project.1425. **Pairing & suggestion** — invert into `source → [tests]`. Build a143 production-to-test project map from `<ProjectReference>` entries; for each144 untested source, mirror its in-project relative path under the referencing145 test project to suggest a path.1466. **JSON emit** — ordered by declaration count desc, then alphabetical.147148## Polyglot engine (tree-sitter)149150### Prerequisites151152- Python 3.10+.153- `pip install tree-sitter-language-pack` (single self-contained wheel that154 bundles parsers for 300+ languages and the high-level `process()` API). No155 native build, no per-language grammar install.156157### Usage158159```powershell160# From the skill folder161python scripts/find_untested_sources.py <repo-root>162163# Restrict to a language (repeatable)164python scripts/find_untested_sources.py <repo-root> --lang python --lang typescript165166# Truncate the report (top 20 by declared API surface)167python scripts/find_untested_sources.py <repo-root> --limit-untested 20 > pairing.json168169# Iterate, highest-API-surface first170$report = Get-Content pairing.json | ConvertFrom-Json171$report.untested_sources | Select-Object -First 10 path, declaration_count, suggested_test_path172```173174Pass `--include-tested` to additionally emit `tested_sources` (omitted by175default to keep the payload small for LLM consumption). Diagnostics go to176stderr; JSON goes to stdout.177178### Output schema179180```jsonc181{182 "repo_root": "<absolute path>",183 "summary": {184 "source_files": 3138,185 "test_files": 761,186 "tested_source_files": 1419,187 "untested_source_files": 1719,188 "orphan_test_files": 15,189 "languages": ["csharp"]190 },191 "untested_sources": [192 {193 "path": "src/Foo/Bar.cs",194 "language": "csharp",195 "declaration_count": 8,196 "declarations": ["Bar", "BarOptions", "IBar", "..."],197 "suggested_test_path": "src/Foo/BarTests.cs"198 }199 ],200 "orphan_tests": [201 { "path": "tests/SomeIntegrationTest.cs", "language": "csharp" }202 ]203}204```205206### How it works2072081. **File discovery** — recursive walk pruning common build/vendor dirs (`bin`,209 `obj`, `node_modules`, `target`, `dist`, `build`, `vendor`, `__pycache__`,210 `.venv`, `.git`, …) and generated files (`.d.ts`, `.g.cs`, `.Designer.cs`,211 `_pb2.py`, `*.min.js`, `AssemblyInfo.cs`, …).2122. **Language detection** — `detect_language_from_path` maps the extension to a213 supported language; unknown extensions are skipped.2143. **Test-vs-source classification** — per-language path heuristics:215216 | Language | Test rule |217 |---|---|218 | Python | path contains `tests/`/`test/`; or filename starts with `test_` or ends `_test.py`; or `conftest.py`. |219 | JS/TS/TSX | path contains `__tests__`, `tests`, `test`, `spec`, `e2e`; or filename contains `.test.`/`.spec.`. |220 | Go | filename ends `_test.go`. |221 | Java | path contains `test`/`tests`; or filename ends `Test.java`/`Tests.java`. |222 | Rust | path contains `tests/`/`benches/`. |223 | C# | path contains `tests/`; or project segment ends `.Tests`/`.Test`/`.UnitTests`/`.IntegrationTests`; or filename ends `Tests`/`Test`. |224 | Ruby | path contains `spec/`/`test/`; or filename ends `_spec.rb`/`_test.rb`. |2252264. **Per-file extraction** — `process(text, ProcessConfig(structure, imports,227 symbols))` returns declared items, raw import statements, and a flat declared228 -name list.2295. **Pairing** — for each test file, union **import resolution** (per language,230 e.g. Python `from pkg.mod import x` → `pkg/mod.py`; Java `import a.b.C;` →231 `a/b/C.java`; C# `using` is namespace-not-file, so a no-op) with **identifier232 overlap** (word-like tokens, length ≥ 4, matched against declared names).2336. **JSON emit** — `untested_sources` ordered by declaration count descending.234235## Limitations (be honest with the agent)236237Both engines are static, parse-only heuristics that trade a little accuracy for238orders-of-magnitude lower cost than coverage. Known gaps:239240- **Reflection / DI-resolved types** referenced only via a string name or241 container resolution won't be detected — the type's short name never appears242 in the test source.243- **Extension methods** invoked as instance methods (C#): the declaring static244 class is not named, so its file is not credited.245- **`var`, target-typed `new()`, pattern matching** lose the type token; the246 file-level union usually still catches it through other references.247- **Short identifier names** (polyglot, < 4 chars) are dropped to avoid noisy248 pairings on names like `id`, `db`, `Tag`.249- **Monorepo path aliases** (TS path mapping, Java module-info) are not250 resolved; a suffix-match fallback may pick the wrong source if two files share251 a trailing path segment.252253For these cases, run actual coverage (`coverage-analysis`) on the unpaired254candidates the agent has already triaged.255256## Outputs the agent should consume257258- `untested[*].source` / `untested_sources[*].path` — pick the next source file259 to test (highest declaration count first).260- `*.suggested_test_path` — drop-in target for the new test file; the Roslyn261 engine honors the test project that already `<ProjectReference>`s the source's262 project, so `dotnet sln add` is not needed.263- `source_to_tests` (Roslyn) / `--include-tested` `tested_sources` (polyglot) —264 verify a newly written test file lands in the list for the intended source.265- `orphan_tests` (polyglot) — tests that don't reference any same-language266 source file; useful for triaging stale or integration-only tests.