A tech lead looks after the solution Shop.slnx, with four business projects and four test projects. A pull request changes only the invoice number format in Shop.Billing, yet the pipeline runs every test project. The solution is constructed for this article; the outputs come from real runs with CodeCharter v1.7.0 and the .NET SDK 10.0.402. Each arrow is a ProjectReference:
Shop.Orders ──► Shop.Pricing ──► Shop.Domain
Shop.Orders ──────────────────► Shop.Domain
Shop.Billing ──────────────────► Shop.Domain
tests/Shop.Domain.Tests ──► Shop.Domain
tests/Shop.Pricing.Tests ──► Shop.Pricing
tests/Shop.Billing.Tests ──► Shop.Billing
tests/Shop.Orders.Tests ──► Shop.Orders
Each test project contains one test with an artificial wait of 3, 6, 10 and 20 seconds, standing in for suites of different length. dotnet test on the solution runs everything:
$ dotnet test Shop.slnx
…
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 3 s - Shop.Domain.Tests.dll (net10.0)
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 6 s - Shop.Pricing.Tests.dll (net10.0)
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 10 s - Shop.Billing.Tests.dll (net10.0)
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 20 s - Shop.Orders.Tests.dll (net10.0)
For the billing PR, Shop.Billing.Tests is enough, because no other project references Shop.Billing. A PR in Shop.Pricing is different: Shop.Orders calls the price calculation, so the order tests belong to it too. A tool has to derive this set from the git range and run everything when the case is unclear.
Selection through project references
codecharter coverage receives the PR's range twice. --git-ref sets which changed lines the coverage gate evaluates, and --affected-by narrows the test projects. Both options must name exactly the same range; otherwise the call stops with exit code 64 before any test runs. For the billing PR, CodeCharter selects one test project. The runs in this article also used --no-host and --no-color; the commands are shown without these options:
$ codecharter coverage --git-ref main..HEAD --affected-by main..HEAD
coverage: 1 test project(s) discovered
coverage: building Shop.slnx once for all test projects
coverage: build finished in 23.8s; test projects run without rebuilding
coverage: running up to 4 test projects at once
coverage: [1/1] Shop.Billing.Tests started
coverage: [1/1] Shop.Billing.Tests ok in 17.4s
coverage: run finished in 41.8s
Diff coverage 100% (1/1 changed lines) for the git range 'main..HEAD' meets the required minimum of 100%.
Diff coverage: 1/1 changed lines = 100% (required 100%, source: inherited, git ref: main..HEAD). …
Without --min-diff-coverage, the diff gate inherits the general coverage threshold ("source: inherited"), whose built-in default is 100%. CodeCharter reaches the selection in three steps. It reads the changed files with git diff --name-status and assigns each file to the projects whose directory contains it. It then searches the ProjectReference graph backwards for every project that references one of these projects, directly or through intermediate projects. From this closure it runs the test projects it found. CodeCharter reads the references from the .csproj files without evaluating MSBuild. If a project file is not valid XML, CodeCharter runs every test project.
For the pricing PR, it is two test projects, Shop.Pricing.Tests and Shop.Orders.Tests. If a PR changes the method CustomerId.IsValid in Shop.Domain, all four run, because every project in the solution references Shop.Domain. The console line "1 test project(s) discovered" counts the selected test projects, not the discovered ones. Which suites were skipped appears neither on the console nor in the CLI's JSON report; the MCP command run_coverage returns the list in the coverageScope field.
Project level and type level
At type level, the closure of the domain change would be smaller. graph impact shows which types use CustomerId:
$ codecharter graph impact Shop.Domain.CustomerId Shop.slnx
Dependents by distance (1 level(s)):
Distance 1 (3):
Shop.Billing.InvoiceNumber (class) …\src\Shop.Billing\InvoiceNumber.cs:6
Shop.Billing.Tests.InvoiceNumberTests (class) …\tests\Shop.Billing.Tests\InvoiceNumberTests.cs:6
Shop.Domain.Tests.MoneyTests (class) …\tests\Shop.Domain.Tests\MoneyTests.cs:5
…
Two test projects reach the type; the order and pricing tests do not. Test selection still does not use this graph. It knows signatures and resolved calls, and according to its notice text it does not represent dynamic calls. It follows that it also misses reflection and files a test reads at run time. The closure over project references is coarser. It contains every test project that includes the changed project through a ProjectReference, however the code inside is called. A test project that includes the assembly as a Reference or as a NuGet package is missing from it.
Finer techniques therefore record the dependencies while the tests run. Ekstazi records, for each Java test class, the files it loads or opens. In the study by Gligoric, Eloussi and Marinov, it selected on average 14% of the test classes across 615 revisions of 32 Java projects. The time for analysis, execution and dependency collection fell on average to 68% of a full run, and to 46% for suites over one minute. For short suites, Ekstazi was sometimes slower than the full run. Microsoft offers Test Impact Analysis, a selection per test method in Azure Pipelines. According to that page, it does not support .NET Core.
Build files and files outside the projects
A PR that changes only the Directory.Build.props at the repository root touches no .cs file. The file applies to every project below it, though, and CodeCharter runs every test project:
coverage: 4 test project(s) discovered
…
Diff coverage gate passed: the git range 'main..HEAD' changed no measurable lines.
The same rule applies at the root to Directory.Build.targets, Directory.Packages.props, global.json, NuGet.config, .gitattributes, .codecharter/config.yml, .codecharter/config.local.yml, .codecharter/codecharter.lock.json and every solution file. The output does not state the reason for the widening. If a PR instead adds a Directory.Build.props under src/Shop.Billing/, it applies only to the projects in that directory and below. CodeCharter then again selects only Shop.Billing.Tests. A file that a project brings in through <Import>, or includes as a linked item outside its directory, such as <Compile Include="../Shared/TaxRules.cs" Link="TaxRules.cs" />, selects that project. CodeCharter does not resolve an import path with property functions, except for a single $([MSBuild]::GetPathOfFileAbove(...)). If an import stays unresolved, every changed MSBuild file such as .props or .targets widens the run to every test project.
A change to README.md at the root also runs all four test projects. The file lies in no project directory, and CodeCharter cannot know whether a test reads it. For files that provably no build and no test reads, there is a list in .codecharter/config.yml:
coverage:
affected-by-inert-paths:
- "changelog.d/**"
With this entry, the billing PR with its changelog fragment changelog.d/42.changed.md again runs only Shop.Billing.Tests. The list is empty by default, and CodeCharter does not check the declaration. If a test does read a declared file, the run skips exactly the suite that would have noticed a change to it. If a range changes only declared files, every test project still runs; otherwise the gate would have no coverage file to evaluate. A directory such as docs/ does not belong in the list when tests read examples from it.
Completeness check
After the test run, CodeCharter checks every changed .cs file with a changed executable line against the coverage data. If such a file appears in no coverage file, the run ends with exit code 3 and names it. In the case, a PR adds the class CreditNote without a test. A full run on main wrote the coverage files beforehand, and --skip-tests evaluates these files, in which the new file is missing:
$ codecharter coverage --skip-tests --git-ref main..HEAD --affected-by main..HEAD
coverage: run finished in 1.0s
…
--affected-by completeness check failed: changed file '…\src\Shop.Billing\CreditNote.cs' has no coverage data at all. …
The full text advises running without --affected-by, widening the selection or adding the file to coverage.exclude. In the normal run of the same PR, the check does not trigger. For Shop.Billing.Tests, coverlet instruments the whole Shop.Billing module and reports CreditNote.cs with zero hits. In that run, the diff gate catches the untested line with 0/1 changed lines = 0% and exit code 1.
The check therefore asks whether any data exists at all, not whether the right tests ran. If a selected test project covers a file while a skipped one would have found a functional bug, the check does not notice. Also exempt are files in test projects, deleted files, files in coverage.exclude and files from projects that no test project references.
A console project Shop.Tools shows the last case: it references only Shop.Domain and has no test project of its own. If a PR changes only its Program.cs, the reverse closure selects no test project:
$ codecharter coverage --git-ref HEAD~1..HEAD --affected-by HEAD~1..HEAD
coverage: 0 test project(s) discovered
coverage: building Shop.slnx once for all test projects
coverage: build finished in 15.9s; test projects run without rebuilding
coverage: running test projects one at a time
coverage: run finished in 15.9s
No coverage data was produced or found.
The run ends with exit code 3. Without --affected-by, the same range passes with "changed no measurable lines" and exit code 0, because no test measures Shop.Tools. CodeCharter therefore does not wave the empty selection through. The message does not say, however, that no test project reaches the changed projects. Test projects that address an application only over HTTP or a database and do not reference it are invisible to the closure as well.
Measured saving
The table summarises the progress lines of single runs; each row is one run. All runs are codecharter coverage --git-ref main..HEAD, with or without --affected-by. The test phase is "run finished" minus "build finished". The machine was building for other projects at the same time, and this load moved the build times between 4.6 and 41.5 seconds and the test phases as well. Shop.Billing.Tests took 12.9 to 26.5 seconds depending on the run.
| PR | Execution | Test projects | Test phase |
|---|---|---|---|
| Billing | all, parallel (up to 4) | 4 | 26.6 s |
| Billing | --affected-by, parallel |
1 | 18.0 s |
| Billing | all, --max-parallel 1 |
4 | 75.5 s |
| Billing | --affected-by, --max-parallel 1 |
1 | 16.1 s |
| Pricing | all, parallel | 4 | 25.2 s |
| Pricing | --affected-by, parallel |
2 | 30.0 s |
| Pricing | all, --max-parallel 1 |
4 | 51.7 s |
| Pricing | --affected-by, --max-parallel 1 |
2 | 33.5 s |
Because of the load, the table shows the direction, not the exact saving. Run serially, the selection saves the run time of the suites it leaves out. The two serial runs over all four suites took 75.5 and 51.7 seconds. For the billing PR, the selection therefore saves roughly 36 to 59 seconds. Run in parallel, the longest suite determines the test phase, in the case Shop.Orders.Tests with 23 to 29 seconds. The billing PR saves it, the pricing PR does not, and its selection takes as long as all four suites. The difference between 30.0 and 25.2 seconds is within the noise of the load. --affected-by does not shorten the build: for the single solution at the root, CodeCharter runs dotnet restore and dotnet build in full, even for a single test project.
In an industrial monorepo, a selection that also takes build and non-code files into account shortened the whole pipeline. Elsner et al. examined 397 pull requests at IVU Traffic Technologies, with C/C++, Java and more than 4,000 Maven modules. Depending on the release branch, the technique selected on average 25 or 52% of the Java test classes, measured against a full run. It also builds only the Maven modules the selected tests need; this cut the build step by 53% on average. The pull request pipeline ran on average 50 and 63% shorter in the authors' two comparisons. The shorter build contributes to that. CodeCharter, in contrast, builds the whole solution. In a sample of 50 of the 305 runs with missed failures, none traced back to the PR. The measurements concern neither .NET nor CodeCharter.
Comparison with dotnet-affected
dotnet-affected is a free tool on nuget.org (MIT licence). It evaluates the MSBuild project graph and writes the affected projects as a traversal project affected.proj. On the same case, v7.0.1 makes the same selection as CodeCharter for Billing, Pricing, Domain and both Directory.Build.props files. For the billing PR, dotnet test affected.proj took 19.7 seconds of total time in one run, including restore and build, without coverage. The number is not comparable with the test phase in the table. Only Shop.Domain, Shop.Billing and Shop.Billing.Tests are built, not the other five projects.
For the README change, it finds nothing and ends with exit code 166. The tool's README recommends skipping the rest of the pipeline in that case:
$ dotnet-affected --from main -f text --dry-run
No affected projects where found for the current changes
CodeCharter runs every test project for the same PR. For a README, both answers are defensible. It follows that for a JSON file outside the project directories that a test reads, only the full selection is right. dotnet-affected ignores the changelog fragment without any configuration; CodeCharter needs the inert list for it.
For a pipeline without a coverage gate, dotnet-affected is the leaner choice, provided the pipeline handles exit 166 and assesses files outside the projects itself. With a coverage gate, CodeCharter adds the completeness check and the full run for unclear files. dotnet test on the whole solution remains the better choice when all suites together take hardly longer than restore and build. The same holds when the longest suite depends on a project that almost every PR changes. When tests use services and files outside the project graph, running everything is also the better choice.
Integration in CI
In the PR workflow, CodeCharter needs the base commit; otherwise resolving the range fails. The error message recommends actions/checkout with fetch-depth: 0 for this:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Coverage of the affected test projects
run: >
codecharter coverage
--git-ref origin/main..HEAD
--affected-by origin/main..HEAD
The snippet assumes an installed and licensed CLI and a .NET environment. On main, the tech lead runs the same check without --affected-by after every merge. That run also executes the tests that depend on other projects over HTTP or a database. Coding agents call the selection through the MCP command run_coverage with git_ref and affected_by. Options and exit codes are described in the coverage documentation. What the gate says about the tests that ran is covered in the article on coverage gates with diff coverage and mutation testing.