powershell-write-tests
Skill24 starsChanged 3 days agoMITView on GitHub
Write or extend Pester 6 tests for existing PowerShell code, following this repository's testing rules. Use when asked to add tests, raise coverage, or test a PowerShell function, script, or module.
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .claude/rules/powershell-standards/copilot-instructions.mdCopilot instructions
- .github/copilot-instructions.mdCopilot instructions
- powershell-ci-pipelineSkill
- powershell-credential-scanSkill
- powershell-loggingSkill
- powershell-module-helpSkill
- powershell-new-functionSkill
- powershell-new-moduleSkill
- powershell-performance-reviewSkill
- powershell-reviewSkill
- powershell-security-reviewSkill
- powershell-write-testsSkill
- powershell-ci-pipelineSkill
- powershell-credential-scanSkill
- powershell-loggingSkill
- powershell-module-helpSkill
- powershell-new-functionSkill
- powershell-new-moduleSkill
- powershell-performance-reviewSkill
- powershell-reviewSkill
- powershell-security-reviewSkill
- powershell-write-testsSkill
- powershell-ci-pipelineSkill
- powershell-credential-scanSkill
- powershell-loggingSkill
- powershell-module-helpSkill
- powershell-new-functionSkill
- powershell-new-moduleSkill
- powershell-performance-reviewSkill
- powershell-reviewSkill
- powershell-security-reviewSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Read .github/instructions/powershell-pester.instructions.md first, unless it is already loaded.
- Very specific: line 13
Read the code under test completely: its parameters and parameter sets, validation attributes, output type, every catch, and every call …
- Very specific: line 16
Look at an existing test file in the repository.
- Very specific: line 20
Write the file so that it runs on its own: a versioned #Requires for Pester, the code loaded in a top-level BeforeAll, and test data built …
- Distinctive: line 26
Run the tests. A test that passes on its first run has not been shown to work: break the behaviour it covers, or the expected value, once …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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
Write Pester tests for PowerShell code
Read .github/instructions/powershell-pester.instructions.md first, unless it is already loaded. It
holds the rules, a complete test file, and a table of assertion behaviour.
Steps
- Read the code under test completely: its parameters and parameter sets, validation attributes,
output type, every
catch, and every call that leaves the process (network, files, other modules, the clock). - Look at an existing test file in the repository. Keep its assertion style and layout. In a new
file use the Pester 6
Should-*assertions. - List the behaviours to test before writing any: each parameter set, the documented output, each
validation failure, each error path, pipeline input, and for a
Test-function both outcomes. - Write the file so that it runs on its own: a versioned
#Requiresfor Pester, the code loaded in a top-levelBeforeAll, and test data built inBeforeDiscovery. - Mock only what crosses a boundary. For code inside a module, pass
-ModuleNametoMockandShould-Invoke, and reach private functions withInModuleScope. - Make every test able to fail: assert specific values, assert the count before reading by index, and
assert expected errors with
Should-Throwor by counting error records. - Run the tests. A test that passes on its first run has not been shown to work: break the behaviour it covers, or the expected value, once to see it fail, then restore it.
Report
Say which behaviours are covered and which are not, the pass and fail counts, and the coverage figure if you measured it. If a test exposes a defect in the code, report the defect; do not weaken the test to make it pass, and do not change the code under test unless the user asked for that.
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.

