testability-obstacle
Skill1.1k starsChanged 23 days agoMITView on GitHub
MUST USE for C#/.NET deterministic tests that require the smallest production seam for DateTime/Task.Delay/File/Environment/Guid/Random, static API preservation, nested/parallel overrides, or no real I/O. USE ONLY when the target workspace contains C# source plus a .csproj or .sln. DO NOT USE for audits, bulk migration, code that already has an injectable seam, or an explicit migration to a user-named existing abstraction (migrate-static-to-wrapper). Use instead of general test generation when the requested test is impossible without a production edit and seam selection is still open.
We split this skill into the rules it gives an agent
21 rules. About 0 are common, 16 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 57
Read the target production path and its existing tests.
- Distinctive: line 61
If an adequate seam already exists, stop refactoring and use it.
- Distinctive: line 83
When the provider itself is mutable (for example an in-memory store or fake time provider), establish a fresh provider inside each parallel …
- Distinctive: line 102
default to the real production dependency.
- Distinctive: line 103
avoid a process-global mutable fake that makes tests non-parallel.
- Very specific: line 105
Use built-in fake-time-aware overloads instead of inventing an IDelay wrapper:
- Very specific: line 113
Test delayed behavior by starting the operation, proving it is incomplete, advancing FakeTimeProvider, then awaiting it.
- Distinctive: line 136
Keep the production change mechanical:
- Distinctive: line 139
Default implementations delegate directly to the original API.
- Distinctive: line 141
Keep existing public signatures unless the user explicitly permits an API change.
- Distinctive: line 142
Do not move business logic into the wrapper or fix unrelated production bugs.
- Very specific: line 159
Update every composition root or constructor call affected by the seam.
- Very specific: line 173
Use the repository's existing test project.
- Distinctive: line 180
no environment mutation, external process, console input, or network.
- Distinctive: line 182
Before authoring a test, inspect its test project and follow the existing framework, global-using, and assertion conventions.
- Very specific: line 211
Do not add InternalsVisibleTo when an existing public seam already accepts the fake or the test project can otherwise supply it.
- Distinctive: line 218
Run the affected production build and the narrowest targeted test command.
- Distinctive: line 219
Run a repository-level test command only when the user requested broad validation, the repository contract requires that entry point, or …
- Distinctive: line 223
every production change is required by the seam.
- Distinctive: line 224
no real ambient resource is used by the new tests.
- Distinctive: line 231
When a new test does not compile, correct its imports, assertion overload, or async test shape against the existing test framework before …
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Resolve a Testability Obstacle
Introduce the smallest behavior-preserving seam needed to test a specific C# behavior, then add deterministic tests that prove both the behavior and the seam. The production edit is a means to the requested test, not an invitation to redesign adjacent code.
When to Use
- A requested test would otherwise read/write the real filesystem.
- Behavior depends on the current time, delay, random value, environment, console, process, or another ambient dependency.
- The user explicitly permits or requests a safe production seam.
- Existing tests cannot control a dependency without process-global mutation.
When Not to Use
- The dependency is already injected or passed as an argument. Write tests with
a fake through the existing seam using
code-testing. - The user wants a repository-wide testability audit. Use
detect-static-dependencies. - The user wants wrappers generated but not call sites/tests changed. Use
generate-testability-wrappers. - The user requests a broad mechanical migration. Use
migrate-static-to-wrapper, then generate tests separately. - The user already selected an existing replacement such as
TimeProviderorIFileSystemand asks to migrate call sites to it. Usemigrate-static-to-wrapper, which also updates affected tests. - The code is not C#/.NET.
Inputs
| Input | Required | Description |
| Behavior to test | Yes | The method/workflow and expected observable behavior |
| Target scope | No | Discover the narrowest relevant file/project when omitted |
| Allowed production changes | No | Default to the minimum internal/constructor seam |
Workflow
Step 1: Prove the obstacle
Read the target production path and its existing tests. Identify the exact ambient operation preventing a deterministic test and the behavior that must remain unchanged. Do not run a repository-wide static scan for a single-class request.
If an adequate seam already exists, stop refactoring and use it. This skill adds no value when a fake can already be supplied.
Step 2: Select the smallest safe seam
Choose by dependency and repository constraints:
| Dependency | Preferred seam |
| Current time / timers | Inject TimeProvider; use FakeTimeProvider in tests |
| Filesystem | Existing repository abstraction; for one write/read operation use an injected delegate when conventions allow, otherwise a one-member interface or an already accepted System.IO.Abstractions |
| HTTP | Existing typed HttpClient/handler or IHttpClientFactory seam |
| Randomness | One final generated value: inject Func<int> and keep range selection in the real default; inject Func<int, int, int> only when range arguments are behavior the test must verify; multiple operations/state: inject Random or a minimal generator interface |
| Environment/console/process | Minimal interface containing only members used by the target |
The scoped AsyncLocal<T> rule applies to every static API that must retain its
public static shape — clocks, filesystem access, environment lookups, identity
generation, and randomness. The scope captures and restores the previous value;
never implement Dispose() as an unconditional assignment to null.
Store the provider/value itself in AsyncLocal<T>. Do not put a mutable
Stack<T>, list, or other shared mutable collection in the slot: child
execution contexts can inherit the same object and corrupt each other's nesting.
When the provider itself is mutable (for example an in-memory store or fake time
provider), establish a fresh provider inside each parallel flow rather than
mutating one inherited instance from a parent context.
Constructor injection is the default for instance classes. Reuse the repository's DI and naming conventions, but do not add a DI container to a class library just to satisfy this workflow.
Preserve the existing public construction surface unless the user authorizes an API change. Keep a public parameterless constructor as the real-dependency default and place a test-only delegate/provider constructor at the narrowest visibility the test project can reach. Do not turn the seam into a new public optional parameter merely for test convenience.
For a static class or a public API that cannot change, use a scoped ambient seam only when constructor/parameter injection is impossible. The override must:
- flow across
await(AsyncLocal<T>, not[ThreadStatic]); - return
IDisposableand restore the previous value, including nested scopes; - default to the real production dependency;
- avoid a process-global mutable fake that makes tests non-parallel.
Use built-in fake-time-aware overloads instead of inventing an IDelay wrapper:
| Ambient operation | Replacement |
Task.Delay(delay, token) | Task.Delay(delay, timeProvider, token) |
new CancellationTokenSource(delay) | new CancellationTokenSource(delay, timeProvider) |
PeriodicTimer(period) | new PeriodicTimer(period, timeProvider) when the target framework provides it |
Test delayed behavior by starting the operation, proving it is incomplete,
advancing FakeTimeProvider, then awaiting it. For a deadline or boundary,
advance to immediately before the deadline and assert the task is still
incomplete before advancing across it; an immediate post-start assertion alone
does not prove the boundary. Never wait for wall-clock time.
For a nested ambient override, each scope captures the value active when it
starts and restores that value exactly once. Dispose scopes in LIFO order with
using/finally; never reset the slot unconditionally to null. Tests must
observe the outer value after an inner scope ends normally and, when requested,
after an exception unwinds the inner scope. Use distinct values so clearing the
slot cannot accidentally pass. Also overlap independent async flows and assert
that each sees only its own fresh override. Do not mutate process environment
variables to test an environment seam.
var previous = s_provider.Value;
s_provider.Value = provider;
return new RestoreScope(() => s_provider.Value = previous);Step 3: Preserve behavior and API shape
Keep the production change mechanical:
- Wrap only members used by the target behavior.
- Default implementations delegate directly to the original API.
- Preserve exceptions, path handling, time zone, and
DateTime.Kind. - Keep existing public signatures unless the user explicitly permits an API change.
- Do not move business logic into the wrapper or fix unrelated production bugs.
Deterministic serialized text is a deliberate exception to preserving ambient
platform formatting. If the user asks for exact reproducible output across
platforms, use the format's explicit separator (use literal \n when none is
specified) and assert that literal content. Keep Environment.NewLine only
when platform-native output is part of the existing contract.
For time replacements:
DateTime.UtcNow->timeProvider.GetUtcNow().UtcDateTimeDateTime.Now->timeProvider.GetLocalNow().LocalDateTimeDateTimeOffset.UtcNow->timeProvider.GetUtcNow()DateTimeOffset.Now->timeProvider.GetLocalNow()
Step 4: Keep production defaults wired
Update every composition root or constructor call affected by the seam. Production
must still use real time/filesystem/etc. by default. If the project uses DI,
register the default implementation with the lifetime matching repository
conventions. If it does not use DI, compose explicitly; do not introduce a
container.
An existing manual factory must pass the real dependency explicitly (for example,
new ExpirationPolicy(TimeProvider.System)). Do not move responsibility into an
optional constructor or add an optional provider parameter to the factory.
Build the affected production project before writing tests. A compile failure here is a seam problem, not a test problem.
Step 5: Write deterministic tests
Use the repository's existing test project. If none exists, invoke
scaffold-dotnet-test-project first.
Tests must supply controlled dependencies:
- fixed/advanced time rather than wall-clock waiting;
- an in-memory fake filesystem or hand-rolled fake rather than temp/real files;
- no environment mutation, external process, console input, or network.
Before authoring a test, inspect its test project and follow the existing framework,
global-using, and assertion conventions. Use the framework packages already referenced
by that project; never add a hand-rolled FactAttribute, a substitute test-framework
type, or unrelated test-project plumbing to make a test compile.
Assert the requested business result and at least one interaction/state observable that proves the fake dependency drove the path. Include a production-default test only when it can remain deterministic; never touch the real filesystem merely to prove the adapter delegates.
Cover every explicitly requested behavior and edge case. A theory or shared helper may keep the suite compact, but do not drop a case to minimize test count or replace retained tests with a smaller set. The seam should be minimal; the verification should still be complete.
Choose the narrowest seam that supports the behavior. A single
File.WriteAllText call can be an injected Action<string, string> with a real
default; do not create an interface, implementation, friend-assembly setting,
and extra project wiring unless repository conventions or multiple operations
justify them.
Preserve the public API surface as well as existing signatures. Do not add a
public dependency-injecting constructor solely for tests. When a class currently
has only its implicit public parameterless constructor and the exact test
assembly is known, keep that constructor behavior and make the test-only
constructor internal; an InternalsVisibleTo entry is justified in this narrow
case because it prevents the seam from becoming public API. Prefer an existing
repository friend-assembly convention when one is present.
Do not add InternalsVisibleTo when an existing public seam already accepts the
fake or the test project can otherwise supply it. Friend-assembly access is
justified only when the chosen minimum constructor/delegate seam must remain
internal to preserve the public API and the exact test assembly is known.
Step 6: Verify the complete path
Run the affected production build and the narrowest targeted test command. Run a repository-level test command only when the user requested broad validation, the repository contract requires that entry point, or the seam changes shared composition used beyond the target. Re-read the diff and confirm:
- every production change is required by the seam;
- no real ambient resource is used by the new tests;
- current-time semantics and public behavior are preserved;
- existing tests were not replaced or duplicated.
Inspect the test summary, not only the exit code. Zero discovered tests, a build without the requested test run, or any failing/erroring test means the task is incomplete. Fix discovery/execution and rerun before reporting success. When a new test does not compile, correct its imports, assertion overload, or async test shape against the existing test framework before changing the production seam; do not emulate missing framework APIs in source. For a static ambient seam, completion requires executed tests for substitution, nested restoration, exception restoration when requested, and overlapping async-flow isolation; production compilation alone is never sufficient. Capture the passing test count or requested test names in the handoff. If no test was discovered or the output does not prove execution, correct the project/test source and rerun rather than reporting the seam as validated.
Output Contract
Provide a compact Requirement | Evidence table. Cite the production seam,
production default wiring, exact test names, and passing commands. If a package
restore or build blocks validation, report that blocker rather than claiming the
tests pass.
Validation
- The original obstacle was concrete and in the requested path.
- An existing seam was reused when available.
- The new abstraction exposes only members required by the target behavior.
- Production defaults still delegate to the original dependency.
- The seam did not enlarge the public API when an internal test seam was sufficient.
- Time conversions preserve local/UTC and
DateTime.Kindsemantics. - Static ambient overrides are async-safe, scoped, nested, and reversible.
- New tests use fixed/in-memory dependencies and no real I/O or wall clock.
- Production build and targeted/repository tests pass with at least one requested test discovered.
Common Pitfalls
| Pitfall | Corrective action |
| Refactoring before proving a blocker | Reuse an existing seam and write the test directly |
| Wrapping an entire static API | Expose only members exercised by the target |
Converting UtcNow with .DateTime | Use .UtcDateTime to preserve DateTimeKind.Utc |
| Mutable static fake shared by tests | Use constructor injection or a scoped AsyncLocal<T> override |
| Adding DI to a library with no container | Compose the dependency explicitly |
| Using temp files as a shortcut | Supply an in-memory fake; the scenario requires no real I/O |
| Stopping after the refactor builds | Write and run the behavior tests that justified the seam |
| Reporting a zero-test run as success | Fix discovery and require the requested tests to execute and pass |
Trending
Quiet since September.about the whole repository
Who's talking about microsoft/testfx
- Stack Overflow“App.config not being loaded in .Net Core MSTests project”Stack Overflow · Feb 24, 2019 · 35 votes
- Stack Overflow“Visual Studio Test Explorer doesn't run tests after changes”Stack Overflow · Dec 21, 2022 · 31 votes
- Stack Overflow“DataTestMethod vs TestMethod”Stack Overflow · Dec 3, 2019 · 19 votes
- Stack Overflow“ConfigurationManager.AppSettings is always empty”Stack Overflow · May 5, 2020 · 17 votes
- dotnet/sdk“[Proposal]: Add Microsoft.NET.Sdk.Testing”GitHub · Jun 7, 2025 · 10 reactions
The biggest 5 of 68 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 68
Talked about on GitHub and Stack Overflow (68 times).
On GitHub · 41
- Jun 7, 2025[Proposal]: Add Microsoft.NET.Sdk.Testing — dotnet/sdksays it tested it10 reactions · 15 comments
- Feb 4, 2025Dependabot job fails due to attempt to update packages referenced via an MSBuild SDK — dependabot/dependabot-core9 reactions · 13 comments
- Feb 22, 2024Microsoft Testing Platform for xUnit — xunit/visualstudio.xunitsays it tested it6 reactions · 19 comments
- Dec 3, 2018DataTestMethod vs TestMethod — microsoft/testfx-docs6 reactions · 4 comments
- Feb 19, 2024Microsoft Testing Platform for NUnit — nunit/nunit3-vs-adaptersays it tested it5 reactions · 1 comment
36 more on GitHub
- Dec 19, 2023Arcade should opt into `BuildWithNetFrameworkHostedCompiler` by default — dotnet/arcade5 reactions · 18 comments
- Nov 24, 2025Native support for Microsoft.Testing.Platform? — danielpalme/ReportGeneratorsays it tested it4 reactions · 3 comments
- Oct 31, 2025Selecting test runner without global.json — dotnet/sdk3 reactions · 2 comments
- Jul 15, 2025[Analyzer Proposal]: Don't use `stringBuilder.Append(new string(c, repeatCount))` — dotnet/runtime3 reactions · 3 comments
- Jul 13, 2025Allow `dotnet test --list-tests json` — dotnet/sdk3 reactions · 7 comments
- Jul 9, 2025Improve output of `dotnet test` with MTP — dotnet/sdk3 reactions · 6 comments
- Jan 30, 2024Support for the new test runner — nunit/nunit3 reactions · 3 comments
- Oct 17, 2017[ExcludeFromCodeCoverageAttribute] should be applicable to assemblies — dotnet/runtime3 reactions · 12 comments
- Sep 2, 2026chore(deps): update mstest to 4.4.0 — thomhurst/TUnit2 reactions · 3 comments
- Dec 17, 2025[MTP] Cannot switch off terminal logger when building during dotnet test — dotnet/sdk2 reactions
- Oct 8, 2025Bump MSTest.TestFramework from 3.11.0 to 4.0.0 — files-community/Files2 reactions · 1 comment
- May 27, 2025Dependabot Ignores Configuration File Settings in latest Version — dependabot/dependabot-core2 reactions · 7 comments
- May 20, 2025Add `-vs` and `-vscode` to build scripts — dotnet/arcade2 reactions · 8 comments
- Mar 14, 2025Add template for dotnet.config to dotnet new — dotnet/sdk2 reactions · 2 comments
- Jan 16, 2024An Allure adapter for MSTest — allure-framework/allure-csharp2 reactions · 2 comments
- Apr 10, 2018Added docs for dynamic data display name — microsoft/testfx-docs2 reactions · 1 comment
- Sep 3, 2026chore(deps): update microsoft.testing — thomhurst/TUnit1 reaction · 3 comments
- Mar 16, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/FAnsiSql1 reaction
- Mar 16, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/libarchive.net1 reaction
- Mar 16, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/RDMP1 reaction
- Mar 16, 2026sdk(deps): Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/CsvHandler1 reaction · 1 comment
- Mar 16, 2026chore(deps): bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/SharpDicom1 reaction
- Mar 16, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/nccid1 reaction
- Mar 15, 2026chore(deps): bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/filestats1 reaction
- Mar 15, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/MCPsharp1 reaction
- Mar 15, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/SynthEHR1 reaction
- Mar 15, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/TypeGuesser1 reaction
- Mar 15, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/LineReader1 reaction
- Mar 15, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/DicomTypeTranslation1 reaction
- Mar 12, 2026Bump dotnet-sdk from 10.0.103 to 10.0.201 — jas88/dcm2csv1 reaction
- Mar 11, 2026chore(deps): bump dotnet-sdk from 10.0.103 to 10.0.200 — jas88/PACSify1 reaction
- Mar 7, 2025Use Microsoft Testing Platform — martincostello/alexa-london-travelsays it tested it1 reaction · 3 comments
- Feb 17, 2025Bump the mstest group across 1 directory with 2 updates — kusl/fluentassertions1 reaction · 9 comments
- May 25, 2026Bump MSTest.TestAdapter and MSTest.TestFramework — fluentassertions/fluentassertions0 reactions · 8 comments
- May 18, 2026Bump the mstest group with 2 updates — fluentassertions/fluentassertions0 reactions · 3 comments
- May 11, 2026Bump MSTest.TestAdapter and MSTest.TestFramework — fluentassertions/fluentassertions0 reactions · 4 comments
On Stack Overflow · 27
- Feb 24, 2019App.config not being loaded in .Net Core MSTests project35 votes
- Dec 21, 2022Visual Studio Test Explorer doesn't run tests after changes31 votes
- Dec 3, 2019DataTestMethod vs TestMethod19 votes
- May 5, 2020ConfigurationManager.AppSettings is always empty17 votes
- Dec 4, 2020The type or namespace name 'PrivateObject' could not be found6 votes
22 more on Stack Overflow
- Nov 2, 2018'TestContext' does not contain a definition for 'DataRow'5 votes
- Jun 15, 2019Get TestResult in MSTest TestCleanup in C#4 votes
- Nov 14, 2024Does a [TestMethod] have to be public? What consequences are there if it isn't?3 votes
- Aug 26, 2020'Inconclusive' tests are reported as 'not run' by Azure DevOps3 votes
- Sep 18, 2018Guidance for running tests using MSTest v1 in Visual Studio 2017 15.8.13 votes
- Nov 29, 2017Long running unit test marked as passed fails TFS build - Object 'xxx.rem' has been disconnected or does not exist at the server.**3 votes
- Jun 25, 2021use PrivateObject in .net 5 from nugget MSTest.TestFramework2 votes
- Jan 7, 2020MS Test V2 - ClassInitialize behavior when fail2 votes
- Oct 30, 2019Test Methods and Test Class in compiled DLL2 votes
- Jan 15, 2019Use configuration file to specify connection string to define a data source in unit test2 votes
- May 2, 2017Where is MSTest V22 votes
- Oct 15, 2022How to unit test private method in .Net Core application which does not support "PrivateObject"1 vote
- Oct 5, 2022Only first DataRow gets executed in MSTest1 vote
- Feb 4, 2021MS Tests DataTestMethod Timeout for a single test1 vote
- Feb 13, 2020PrivateObject class not found in .Net Core 2.01 vote
- Jan 4, 2020MsTest TestCleanup method not called when an unhandled exception is thrown1 vote
- May 3, 2019Where do I find TestContext.AddResultFile()?1 vote
- Apr 24, 2017Inherited test class from generic base is ignored in MSTest1 vote
- Aug 20, 2025Use MSTest.Sdk for TestHelper0 votes · 1 answer
- Mar 9, 2022Test results are published correctly but not reflected in pipeline Results - Azure devops (Yaml)0 votes
- Dec 22, 2021Testing with empty string using DataRow in MsTestV20 votes
- Feb 6, 2018Why does Visual Studio Always pull in the latest version Unit Test Framework within a solution when older versions are already included0 votes
In this repository62 other files it gives its agents.
- AGENTS.mdAGENTS.md
- eng/common/AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- assertion-qualitySkill
- binlog-failure-analysisSkill
- binlog-generationSkill
- build-parallelismSkill
- build-perf-baselineSkill
- build-perf-diagnosticsSkill
- check-bin-obj-clashSkill
- code-testing-agentSkill
- code-testing-extensionsSkill
- code-testingSkill
- copy-to-output-directorySkill
- coverage-analysisSkill
- crap-scoreSkill
- csharp-expertSkill
- csharp-refactoringSkill
- curation-exceptionsSkill
- detect-static-dependenciesSkill
- directory-build-organizationSkill
- eliminate-redundant-restoresSkill
- eval-performanceSkill
- extension-pointsSkill
- filter-syntaxSkill
- find-untested-sourcesSkill
- generate-testability-wrappersSkill
- grade-testsSkill
- including-generated-filesSkill
- incremental-buildSkill
- item-managementSkill
- migrate-static-to-wrapperSkill
- msbuild-antipatternsSkill
- msbuild-modernizationSkill
- msbuild-serverSkill
- msbuildSkill
- mtp-hot-reloadSkill
- platform-detectionSkill
- property-patternsSkill
- resolve-project-referencesSkill
- run-testsSkill
- scaffold-dotnet-test-projectSkill
- setup-local-sdkSkill
- target-authoringSkill
- test-analysis-extensionsSkill
- test-anti-patternsSkill
- test-gap-analysisSkill
- test-smell-detectionSkill
- test-taggingSkill
- test-value-evidenceSkill
- troubleshoot-binlog-mcpSkill
- writing-mstest-testsSkill
- agentic-workflowsSkill
- behavior-preserving-refactorSkill
- code-reviewSkill
- feature-deliverySkill
- post-release-activitiesSkill
- session-delivery-hygieneSkill
- testfx-acceptance-validationSkill
- testfx-localization-validationSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

