unit-tests
Skill1 starsChanged 6 days agoMITView on GitHub
How unit tests are written with xUnit, Shouldly and NSubstitute - folder layout, naming, Arrange/Act/Assert, testing validators and handlers, and asserting the cancellation token. Use when testing a handler, validator, endpoint or any class in isolation.
16 other projects use a version of this.
Adopted by
Most recently taken up by
- microsoft/vscodetheir own version, first seen Nov 2, 2026
- shangyiy/life-kittheir own version, first seen Nov 1, 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
- shangyiy/life-kit★ 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 repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-a-use-caseSkill
- api-conventionsSkill
- branches-and-pull-requestsSkill
- cancellationSkill
- ci-for-your-solutionSkill
- ci-pipelineSkill
- clean-architecture-layersSkill
- configuration-and-environmentsSkill
- coverageSkill
- csharp-house-styleSkill
- data-access-ef-coreSkill
- database-migrationsSkill
- docker-and-composeSkill
- docs-and-voiceSkill
- errors-and-exceptionsSkill
- expose-a-use-caseSkill
- family-syncSkill
- health-checksSkill
- integration-testsSkill
- json-serializationSkill
- mapping-with-mapperlySkill
- mcp-inspectorSkill
- mediatorSkill
- optional-token-authSkill
- packages-and-dependenciesSkill
- pagingSkill
- presentation-integration-testsSkill
- releasesSkill
- sample-dataSkill
- security-findingsSkill
- serilogSkill
- telemetrySkill
- template-authoringSkill
- test-designSkill
- time-providerSkill
- validationSkill
- writing-a-skillSkill
- xml-docs-and-openapiSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 3 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Create <Class>Tests.cs in the matching folder, for example …
- Very specific: line 29
Use a real CancellationTokenSource so you can prove the token was passed on (cancellation).
- Very specific: line 74
Use Assert.Equal or FluentAssertions.
- Distinctive: line 75
Use Moq. NSubstitute only.
- Distinctive: line 76
Test private methods, or test through the database in a unit test.
- Distinctive: line 78
Write a test that only exists to raise coverage without asserting behaviour.
“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 rule
xUnit for tests, Shouldly for assertions, NSubstitute for fakes. Test folders mirror the source folders. test-design says which tests a change needs; this skill says how to write them. Each test has // Arrange, // Act and // Assert comments and tests one thing.
| Project | Tests |
tests/Application.Tests.Unit | Handlers (repositories faked with NSubstitute) and validators (FluentValidation.TestHelper) |
tests/Presentation.Tests.Unit | Presentation classes we wrote, called directly, with ISender faked where they send requests. Every template has this project; what goes in it depends on what its presentation layer holds |
Test the code we wrote, not the libraries under it. A unit test that only proves ASP.NET Core, Hot Chocolate, Mapperly or the AWS serializer does its job protects nothing of ours. Test our settings, error handlers and filters, transformers, option extensions and parsing, and leave the libraries' own behaviour to the libraries.
Names read as Method_Should<Outcome>_<Condition>: Handle_ShouldThrowException_ReviewDoesNotExist, GetReviews_ShouldReturn_Ok, Validator_ShouldHaveValidationErrorFor_Id.
Steps
- Create
<Class>Tests.csin the matching folder, for exampletests/Application.Tests.Unit/Reviews/Commands/UpdateReview/UpdateReviewHandlerTests.cs. - Handlers: one test for the happy path, one per failure (not found, and so on). Fake each repository with
Substitute.For<I...Repository>()and set returns withReturnsForAnyArgsorReturnson specific arguments. - Assert the result, then assert the calls:
Received(1)with the exact arguments and token, andDidNotReceiveWithAnyArgs()for calls that mustn't happen. - Validators: a static validator instance, one valid case with
ShouldNotHaveAnyValidationErrors(), and a[Theory]per rule withShouldHaveValidationErrorFor(...). - Use a real
CancellationTokenSourceso you can prove the token was passed on (cancellation). - To check a log message, pass a
FakeLogger<T>(Microsoft.Extensions.Diagnostics.Testing) and assert onlogger.Collector: the count, then the level, message and exception ofLatestRecord.
Example
// tests/Application.Tests.Unit/Reviews/Commands/UpdateReview/UpdateReviewHandlerTests.cs
[Fact]
public async Task Handle_ShouldReturnUpdatedReview_ReviewExists()
{
// Arrange
var command = new UpdateReviewCommand
{
Id = Guid.NewGuid(),
Stars = 1
};
var review = new Review(command.Id, command.Stars);
var reviewsRepository = Substitute.For<IReviewsRepository>();
_ = reviewsRepository.UpdateReview(default, default, default).ReturnsForAnyArgs(review);
var handler = new UpdateReviewHandler(reviewsRepository);
using var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;
// Act
var result = await handler.Handle(command, token);
// Assert
result.ShouldBe(review);
_ = await reviewsRepository.Received(1).UpdateReview(command.Id, command.Stars, token);
}// tests/Application.Tests.Unit/Reviews/Commands/UpdateReview/UpdateReviewValidatorTests.cs
var result = Validator.TestValidate(command);
_ = result.ShouldHaveValidationErrorFor(command => command.Id);Don't
- Use
Assert.Equalor FluentAssertions. Shouldly only. - Use Moq. NSubstitute only.
- Test private methods, or test through the database in a unit test.
- Share mutable state between tests through static fields.
- Write a test that only exists to raise coverage without asserting behaviour.
- Re-test a library's behaviour, such as a framework's model binding or a serializer's defaults.
Check
dotnet test tests/Application.Tests.Unit
dotnet test tests/Presentation.Tests.UnitDoes 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.

