/cscheck:finding-test-gapsfrom cscheck
Measures C# unit test gaps via code coverage and mutation testing. Reports code no test runs and mutants tests miss, helping identify where tests are needed.
Ships in cscheck. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Two measures, each for a different kind of gap:
They show how good the tests are, where new tests should go, and whether a new test checks anything. They don't find bugs by themselves: bugs come from reading the code and from properties, as closing-test-gaps describes, though the sweep's reading turns up candidates too. Both suit pure logic with fast, deterministic unit tests, not functional or regression tests, or tests that need a database, the network or real timers.
The tools are three C# file-based apps in this skill's scripts folder, written <skill>/scripts/ below. Run each with dotnet run --file, as below: without --file, a project file in the current folder is built or run instead. The first run of each compiles it in a few seconds, and mutants.cs and candidates.cs restore Roslyn from NuGet then. dotnet takes its SDK from the global.json above the folder it runs in, so in a repo whose global.json pins SDK 8 or 9, run the tools from another folder: mutants.cs and candidates.cs then take the repo as --root <repo>, and mutants.cs builds it with the repo's own SDK. Keep reports, plans and logs in a scratch folder outside the repo, written <scratch> below, and send long output to a log file there rather than reading it all.
--since, step 1). The inputs in scope are everything the code must support, by its types, docs and validation, which for general-purpose code is more than its callers pass today.candidates.cs (step 2): its line that starts Wrote says how many it lists. For more than a few hundred, ask before sweeping: say what it will cost, and offer to start with the members with the most logic and callers.dotnet test -c Release <test project> --collect "Code Coverage;Format=cobertura" --results-directory <scratch>/coverage-1
dotnet run --file <skill>/scripts/uncovered.cs -- <scratch>/coverage-1 [<file or type names, or partial paths>] [--since <ref>]
For a test project with several target frameworks, add -f <framework> to the first command to run one. A Microsoft.Testing.Platform project, such as one using TUnit, collects the same report from its test app: dotnet run -c Release --project <test project> -f <framework> -- --coverage --coverage-output-format cobertura --results-directory <scratch>/coverage-1, where -f is needed only for several target frameworks. Collect each run into a new folder (coverage-2 and so on), since uncovered.cs merges every report under the folder. Given file names, it prints each file's lines not run, its branches partly taken and its members; given none, it ranks the files; given --since <ref>, it shows the changed lines no test ran, in the named files if any, by file name rather than type. Read coverage.md for what the output means and the blind spots.
uncovered.cs, the files' names and --sweep <scratch>/sweep.md. That file gets a row per member, and the output lists each member's callers, which step 2 works from, so keep it in a log in <scratch>. --sweep needs file names and doesn't take --since, so after --since, name the changed files. Put the reasons above in the table's "Not run, and why" column.Read mutants.md before writing any: the kinds that found gaps worth a test, the kinds that were only noise, the spec and how a run behaves.
Writing mutants wherever a recipe seems to fit skips whole members, even ones with about 50 call sites. So sweep, don't sample:
Take the members from the table step 1 started, in source order: uncovered.cs listed each with the uses of its name elsewhere in the repo, its lines not run, and up to four of its uses outside tests and in them, with the arguments each passes. Uses go by name, so a private member shows none and a common name, such as IsMatch, can show only other types': find its callers with find-references. When starting from --since, the scope is the changed members it printed, and read the changed lines it lists that aren't code, since a changed const or signature can change members it doesn't name.
Sweep every member a caller reaches, directly or through the file's other members, and in a library, such as a shared project or a NuGet package, every public member, whether its callers are in the repo or not yet anywhere (step 0): in trial 2 the public members nothing called yet held 17 survivors worth a test. Take code with puzzled comments early (WHY?, ???, a TODO), since nobody has pinned down what it does. Skip the rest as dead code, offer to delete it, and say so, but check a 0 with find-references first, since reflection, serialisers and DI call members by name, and a collection's lookups call Equals and GetHashCode without naming them.
Read the member's tests first, to see what they pin down and what they don't: mutants written with the tests in view are far more often real faults the tests miss. Compare the tests' arguments with the production callers', starting from the uses uncovered.cs listed: a value every caller passes and no test does, such as a null id, the production tolerance or a flag all callers set, is a common gap. But the callers are the least the tests should cover, not the most (step 0). Then list the candidates, which saves writing each mutant's text by hand:
dotnet run --file <skill>/scripts/candidates.cs -- <file> --members <Type.member,member> --coverage <scratch>/coverage-N --out <scratch>/<name>.candidates.json
Name the members as uncovered.cs printed them, and give it the latest coverage folder. The file it writes holds every candidate in the file whichever members are named, so the ids stay the same from one run to the next. It prints each member's candidates, with an id each, and counts those on lines no test runs, which it leaves out, since they can only survive. Keep every one a caller could see, even where you expect a test to kill it, and skip only what's equivalent, the don't-write list, and boundaries whose two sides can't really be equal, such as on an exact instant. Keep those that may not compile too: mutants.cs reports one that doesn't in about a second, which is quicker than sorting them out by hand. For the members whose own logic suits the rest of Stryker.NET's mutations, as mutants.md says, run it again with --rest and --members naming just those.
Then write by hand, for each member, mutants.md's by-hand kinds and those the repo's bug history shows: in the blind trial they were nearly a third of the survivors. Note them in the sweep table's "By hand" column, or why a member has none.
Mutants only change code that's there, so they can't show a missing case: a key no map has, or an enum member one path handles and a parallel path doesn't. Note these as you read, and give them a test over every enum member or key, or one comparing the parallel paths.
While reading, note what a property could check, such as a round trip, an oracle or an invariant, and anything that looks like a bug. Hunt the bug candidates in step 3, where the survivors can point at more.
Keep the plan in the table step 1 started in <scratch>/sweep.md: fill in each member's mutants from the list and by hand, its property (or "none"), and what was skipped and why. Note the missing cases and bug candidates under the headings below it. That way nothing is skipped silently, and no property idea is lost before the tests are written. Write it out whole when you first fill it in, then change it with small edits rather than rewriting it, since in the trials output was the largest cost of a session.
List the mutants in a JSON spec in <scratch>, as mutants.md shows, written with your file-writing tool rather than through the shell, whose quoting mangles find text. Set its candidates to the file candidates.cs wrote, and give each candidate kept by its id alone. For a property from step 1, name it as the expect of the mutants it should kill. Run mutants.cs from the repo root, or with --root, as above:
dotnet run --file <skill>/scripts/mutants.cs -- <json>
It prints how long the mutants should take, a line as each one finishes, and then every result. Run it in the foreground, with a timeout of at least 3 s a mutant (step 0) plus the build, where your agent allows one, so the results come back in one call. Otherwise, or when there's reading left to do, such as the callers of the members swept, run it in the background with its output sent to <json>.log, and wait to be told it has finished rather than reading the log while it runs, since every look costs a turn. Don't edit the library or its tests until it finishes: the results would be for code that has since changed, and in one trial that cost a second sweep.
For each survivor, read the code and say what bug it stands for and why the tests miss it: name a test that runs its line and what its check misses, such as an equality check on a DateTimeOffset, which ignores the offset. It's a gap if the bug is plausible for an input the code must support. Then check the callers, which set its rank, not whether it counts: of the 37 bug candidates in the trials, 33 had at most a 5% chance of being hit by today's callers, and 20 of those were at least 80% likely to be real. Then do one of these:
< to <= in a clamp, where both branches give the same value at equality) and say why, with no test. A dropped defensive copy is equivalent only if neither the input nor the result can change afterwards; orSurvivors cluster around bugs: six on one path sat on two real bugs. So read a cluster of survivors as a bug candidate, and hunt it with those noted while reading, as closing-test-gaps describes, before writing tests.
Group the survivors that need a test by what would expose them: usually an input the tests lack, sometimes a check they make too loosely. One test that covers it usually kills the whole group. In one run, three survivors hid behind the only test date, 2023-01-01, which reads the same with day and month swapped, tests that only used a winter date, when their time zone matched UTC, and a check of a fraction to within a microsecond. A round trip over random dates and a property comparing exact ticks killed all three. A test of time zone handling should set its zone rather than use the machine's, since a mutant using local time is only killed where the zone is off UTC on the dates tested, which a UTC build server never is.
If the request was only to measure, stop here and report the groups with the test each needs. Otherwise write one test per group, preferring a CsCheck property written as writing-cscheck-tests says, and rerun the group's mutants with --only to show it kills them. Take its expected values from the docs, an oracle or a hand calculation, not from what the code returns now: a survivor shows the tests can't tell two versions apart, not which is right, and where only the code can say, the survivor is a bug candidate. Where the input is one known value, such as an expression from a production config, an example test is simpler.
--only rerun is its measure: the group's survivors are the mutants only it should kill, and one that still survives a long run shows the test is hollow.CsCheck_Iter (such as 1000) in the environment of the run, which the tests inherit, to lengthen every check that doesn't pass its own iter: or time:. To settle one survivor, rerun it with --only <id> --filter-only and CsCheck_Time (such as 10), which overrides a check's iter: too. Without --filter-only, a mutant that survives again is rerun against the whole project, where every property takes that long.exclude: one that survives there, rerun against the whole project, is a gap no other test closes. The copy keeps the sweep's own results.Report the few gaps that matter most, ranked, rather than every survivor, written once at the end, from sweep.md after a sweep:
What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/closing-test-gapsHunts for bugs in C# and .NET code by reading it against what should agree with it (its siblings, docs, callers, history and the code it was ported from), probing the edges of what it must support, and confirming each candidate with a small probe or a CsCheck property, ranked by how likely each is to be real and to be live. Use when asked to find bugs or to check that code is right, e.g. "find the bugs in this parser", "is this calendar code right", "what could go wrong in this class", "check this for edge cases". To measure what the tests miss, use finding-test-gaps; to write the tests, writing-cscheck-tests./writing-cscheck-testsWrites CsCheck tests for .NET code that find bugs rather than just pass. Also use it when writing or reviewing unit tests for pure logic, to consider whether a property would find more or could replace them. E.g. "add a CsCheck property for this parser", "write a round trip test for X", "check Equals and GetHashCode agree", "is my new version faster", "model this protocol as a Spec and check the code conforms", "test this class for thread safety", "why does my property pass when the code is broken". Covers Sample, Equality, SampleModelBased, SampleMetamorphic, SampleParallel, Spec, Faster, causal profiling, Single and Check.Hash, and what changed in CsCheck 5. To hunt for the bugs themselves, use closing-test-gaps.npx claudepluginhub anthonylloyd/cscheck --plugin cscheckOther plugins' skills for the same job