unit-tests
Skill10 starsChanged 6 days agoMITView on GitHub
Write or review tests of the smallest piece of code that can be tested on its own, including test doubles (stubs, fakes, mocks), testability seams, and test-first changes. Use for unit tests, TDD, tests that are hard to write because of collaborators or hidden dependencies, or on /unit-tests. Not for choosing inputs (black-box), writing the pass or fail check (test-oracle) or closing coverage gaps (white-box).
16 other projects use a version of this.
Adopted by
Most recently taken up by
- LeanMeanCleanApps/CleanModelContextProtocoltheir own version, first seen Nov 8, 2026
- microsoft/vscodetheir own version, first seen Nov 2, 2026
- GoogleCloudPlatform/cloud-solutionstheir own version, first seen Nov 1, 2026
- 1Shot-API/skillstheir own version, first seen Oct 13, 2026
- bftelman/skillstheir own version, first seen Oct 13, 2026
- karimtrapper/claude-skillstheir own version, first seen Oct 13, 2026
Used with
Projects with it also use auto-perf-optimize, chat-customizations-editor and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
MicrosoftSkillauto-perf-optimize
Run agent-driven VS Code performance or memory investigations. Use when asked to launch Code OSS, automate a VS Code scenario, run the Chat memory smoke runner, capture renderer heap snapshots, take workflow screenshots, compare run summaries, or drive a repeatable scenario before heap-snapshot analysis.
Also in 5 projects that use this
MicrosoftSkillchat-customizations-editor
Use when working on the Chat Customizations editor — the management UI for agents, skills, instructions, hooks, prompts, MCP servers, and plugins.
Also in 5 projects that use this
OpenCortexIDESkilladd-policy
Use when adding, modifying, or reviewing VS Code configuration policies. Covers the full policy lifecycle from registration to export to platform-specific artifacts. Run on ANY change that adds a `policy:` field to a configuration property.
Also in 4 projects that use this
- +9 more from microsoft
Other versions16 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 16
- microsoft/vscode★ 195ksame name
- posit-dev/positron★ 4.3ksame name
- bklit/bklit-ui★ 1.9ksame name
- NeuralInverse/neuralinverse★ 221same name
- genlayerlabs/genlayer-studio★ 180same name
- OpenCortexIDE/cortexide★ 175same name
- GoogleCloudPlatform/cloud-solutions★ 139same name
- cpkt9762/opencode-vscode-ide★ 17same name
- xAmirHamza77/OmniCode★ 12same name
- WordPress/core-contributor-skills★ 10same name
6 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository35 other files it gives its agents.
- AGENTS.mdAGENTS.md
- design-principlesSkill
- experimentationSkill
- groupingSkill
- idea-qualitySkill
- info-foragingSkill
- investingSkill
- listeningSkill
- misfitsSkill
- motivationSkill
- needs-to-signalsSkill
- optionalitySkill
- perspectiveSkill
- purposeSkill
- testingSkill
- verify-before-shipSkill
- resume-deep-diveSkill
- review-resumeSkill
- inspiring-ideaSkill
- next-goalSkill
- side-quest-recommendSkill
- still-want-itSkill
- find-the-argumentSkill
- make-presentation-slideSkill
- agent-evalsSkill
- behavior-viewSkill
- black-boxSkill
- clean-arch-domainSkill
- mutation-testingSkill
- structure-viewSkill
- test-oracleSkill
- user-storiesSkill
- white-boxSkill
- negotiationSkill
- readableSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
The contract, not the code, sets the tests: Every postcondition and state sequence gets a check, and all outcomes of one stimulus share one …
- Very specific: line 25
Test first: Write the test before the code that makes it pass, so each test is seen to fail (testing principle 2).
- Distinctive: line 47
Expected-error tests: if the test code around the action is complex, a declared expected error can come from the wrong statement and mask a …
- Distinctive: line 56
Migrate incrementally: add the new code path beside the old one, let the old one delegate to the new, move tests over, and delete the old …
“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
/unit-tests
The use case for code-level unit tests. Every principle and definition of testing applies unchanged; this skill holds only what is specific to units of code. It makes three choices for that domain. What is under test: a unit, the smallest piece of code that can be tested on its own and assigned to one developer; a unit test sends a stimulus and checks the returned result, the state left behind, or both. Where the oracle comes from: the unit's contract (pre- and postconditions, invariants, state sequences), made explicit before testing. Which faults it models: small slips in code, injected as mutants. The methods supply the detail: inputs and their combinations from black-box, oracles from test-oracle, structural gaps from white-box, suite strength from mutation-testing. Use this skill to write tests or to review a suite; in a review, name each breach once, with its fix, and list behaviors no test covers.
Principles
- Isolate the unit. Collaborators that are not under test are replaced by doubles where a real one would make the test slow, nondeterministic or unable to reach a condition. Isolation is an approximation (
testing§ six general properties): what a double stands in for is not tested here (testing§ Definitions, fixture), so the wiring needs tests at higher levels. - The contract, not the code, sets the tests. Every postcondition and state sequence gets a check, and all outcomes of one stimulus share one test; a limit the contract ignores is a gap to report (
testingprinciples 3 and 4, § Definitions: contract). - Prefer the least intrusive double that serves, from least to most intrusive: dummy or stub, fake, spy, mock. Stub when the collaborator only needs to be there and return canned answers; fake when the test needs realistic behavior that stubbing cannot give; spy to reveal internal state; mock when interactions matter or behavior must change during the test. Which outcomes need an interaction check follows the oracle rule "stub queries, mock actions" (
test-oracle). Mocks can be much work, brittle, hard to maintain and read, and often unnecessary; use them where interactions matter. - Design units to be testable. Testability (
testing§ Definitions) is decided by the design: see the seams below. - Test first. Write the test before the code that makes it pass, so each test is seen to fail (
testingprinciple 2). - Treat test code like production code. It is read and changed as often.
Test doubles
- Kinds: a dummy only fills a parameter slot, a stub returns canned answers, a fake is a simpler working version, a spy records calls or reveals hidden state, a mock checks expected interactions and can also act as a stub or a spy. In general testing usage "stub" means any simulated collaborator; among doubles it is the simplest kind.
- Why doubles: isolation, speed, determinism, simulated special conditions and injected faults, access to hidden information, and tests that run before the real collaborator exists.
- Substitutability: a double and the real collaborator share an interface, and the double must honor that contract; contract tests written against an interface can then run against every implementation. A double made by inheriting the real implementation can break substitution outside the test; prefer an interface and delegation.
Testability seams
- Five inhibitors: code that cannot be instantiated (environment-bound creation), invoked (hidden or opaque operations), observed (no return value, hidden state, side effects or interactions), substituted (hard-coded collaborators, chains of calls through collaborators) or overridden in a test.
- Inheritance cannot bypass a parent's creation logic. Creating a subclass always runs the parent's construction, so neither a test subclass nor an overridden factory method stops creation logic you cannot change from running, along with its environment-bound effects. Hold such code by composition instead: put it behind a thin wrapper you control, depend on the wrapper's interface, and double the wrapper.
- Design for it: high cohesion and low coupling; one responsibility per unit, so each test has one reason to fail; extension without modification; small interfaces; dependence on abstractions. Dependency injection, passing collaborators in from outside instead of creating them inside, is the mechanism that achieves dependency inversion, and it is central to testability.
- Hidden logic: split complex hidden logic into simple hidden helpers and a visible unit that holds the complexity, and test hidden methods indirectly through the visible interface; once the complexity is extracted, the simple hidden helpers need no direct tests, because the visible behavior covers them. Don't break visibility at run time, which makes tests brittle and complicated.
- Guidelines: instantiate inside a unit only objects you will never replace with a double; keep test-preventing logic out of creation; avoid globally reached, non-replaceable state and members a test cannot replace where a test needs a double; prefer delegation to inheritance; wrap any external or legacy code you cannot change, not only code you inherit from, in the same way.
- Trade-offs: testability can clash with information hiding and other design principles; it is a matter of balance. Sealing a method against overriding has no easy answer: weigh the cost of misuse against testability, and remember tests can reveal misuse. Shared central resources are natural single instances yet are precisely the ones tests want to replace; make the instance replaceable under an agreed convention.
Test code quality
- Simplicity: small steps and a small fixture. Move nonessential setup into helpers with descriptive names, all at a single abstraction level; a long, noisy arrange hides the behavior.
- Maintainability: factor duplication into setup steps and helpers, and move conditional logic out of tests into helpers; shared setup must still leave each test independent.
- Expected-error tests: if the test code around the action is complex, a declared expected error can come from the wrong statement and mask a failure, so keep only the action that should raise it inside the expectation.
- Injecting a fault in code (
testingprinciple 2): seed a defect or replace part of the production code with a stub until the test fails, then restore it. Never comment out an unfinished test; make it fail. - A parameterized test runs one test logic over rows of input and expected data.
- The eleven practices and their homes: simplicity and maintainability (above); understandability (
testingprinciple 4: names state the behavior;test-oracle: no magic values); essentiality (test-oracle: each check its own verdict, no hyperassertions); single purpose and behavior first (testingprinciples 4 and 3); determinism and independence (testingprinciple 5); fail-ability (testingprinciple 2); comprehensiveness (testingprinciple 7); speed (testingprinciple 6).
Test-driven change
- Red, green, refactor: start from a test name that states the intent, write the test, add only enough code to build, see it fail, make it pass with the smallest change, then improve the design. A hard-coded green step is legitimate work in progress, not a defect; the next failing test forces the generalization. Move in the smallest steps possible, and avoid breaking many tests together.
- An interface change with no new behavior needs no new test: change the interface, fix every use until the code is consistent again, and rerun the suite, which must still pass.
- Migrate incrementally: add the new code path beside the old one, let the old one delegate to the new, move tests over, and delete the old path last; deleting it first breaks many tests at once.
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.

