{"slug":"test-design-2","title":"test-design","summary":"What a complete set of tests is for a change - the happy path, every documented failure, both sides of every boundary, the cancellation token and one request per status code - written as Arrange, Act, Assert with one behaviour per test. Use when deciding which tests to write, rev","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-11-27T19:09:13.244765Z","repo":{"url":"https://github.com/LeanMeanCleanApps/CleanGraphQLApi","stars":13,"forks":7,"license":"MIT","updatedAt":"2026-11-25T23:23:22Z"},"bodyHtml":"<hr>\n<h2>name: test-design\ndescription: What a complete set of tests is for a change - the happy path, every documented failure, both sides of every boundary, the cancellation token and one request per status code - written as Arrange, Act, Assert with one behaviour per test. Use when deciding which tests to write, reviewing tests, fixing a bug, or when coverage is met but you're not sure the behaviour is.\nmetadata:\nscope: shared</h2>\n<h1>Test design</h1>\n<h2>The rule</h2>\n<p>Tests prove behaviour, positive and negative. Coverage is the floor the pipeline checks, not the goal: a change is tested when every behaviour it adds or changes has a test that would fail if that behaviour broke.</p>\n<p>Every test has <code>// Arrange</code>, <code>// Act</code> and <code>// Assert</code> sections, tests one behaviour, and is named <code>Method_Should&lt;Outcome&gt;_&lt;Condition&gt;</code> so a failure reads as a sentence.</p>\n<p>What each kind of code needs:</p>\n<table>\n<thead>\n<tr>\n<th>Code</th>\n<th>Positive cases</th>\n<th>Negative cases</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Validator</td>\n<td>A valid request has no errors; each allowed boundary value passes</td>\n<td>One failing case per rule, asserting the message; each value just outside a boundary fails</td>\n</tr>\n<tr>\n<td>Handler</td>\n<td>The happy path returns the expected result and passes the request's values and the token to the repository</td>\n<td>Each documented failure (not found, conflict) throws the right exception, and later calls don't happen</td>\n</tr>\n<tr>\n<td>Repository</td>\n<td>The right rows come back or change, in the right order, with paging and search applied</td>\n<td>Unknown ids return null or false; nothing else changes</td>\n</tr>\n<tr>\n<td>Endpoint, tool, resolver or function</td>\n<td>One test per documented success status</td>\n<td>One test per documented failure status (validation problem, not found, unauthorised) with the problem body checked</td>\n</tr>\n<tr>\n<td>Behaviour or middleware</td>\n<td>It calls the next step and passes the result through</td>\n<td>It stops the request when it should, and the next step isn't called</td>\n</tr>\n</tbody>\n</table>\n<h2>Steps</h2>\n<ol>\n<li>List the behaviours before writing a test: what the code promises, and every way it can say no. The XML docs and the documented response codes are a good checklist.</li>\n<li>For each range or limit, test both sides: the last value allowed and the first value refused (stars <code>1</code> and <code>5</code> pass, <code>0</code> and <code>6</code> fail; limit <code>50</code> passes, <code>51</code> fails). Use a <code>[Theory]</code> with <code>[InlineData]</code> for each side.</li>\n<li>Assert outcomes, not just that nothing threw: the returned value, the exception type and message, the status code and body, and the calls made with their exact arguments.</li>\n<li>Assert that the cancellation token reaches every repository call (<code>cancellation</code>).</li>\n<li>On a negative path, assert that the work after the failure didn't happen (<code>DidNotReceiveWithAnyArgs()</code>).</li>\n<li>Fixing a bug? Write the test that shows it first, watch it fail, then fix the code.</li>\n<li>Run the coverage command (<code>coverage</code>) last, to find behaviour you forgot, not to pick lines to cover.</li>\n</ol>\n<h2>Example</h2>\n<pre><code>// tests/Application.Tests.Unit/Reviews/Commands/CreateReview/CreateReviewValidatorTests.cs\n[Theory]\n[InlineData(-1)]\n[InlineData(0)]\n[InlineData(6)]\n[InlineData(100)]\n[InlineData(-100)]\npublic void Validator_ShouldHaveValidationErrorFor_Stars(int stars)\n</code></pre>\n<pre><code>// tests/Application.Tests.Unit/Reviews/Commands/UpdateReview/UpdateReviewHandlerTests.cs\n[Fact]\npublic async Task Handle_ShouldThrowException_ReviewDoesNotExist()\n{\n    // Arrange\n    var command = new UpdateReviewCommand { Id = Guid.NewGuid(), Stars = 5 };\n    var reviewsRepository = Substitute.For&lt;IReviewsRepository&gt;();\n    _ = reviewsRepository.UpdateReview(default, default, default).ReturnsForAnyArgs((Review?)null);\n    var handler = new UpdateReviewHandler(reviewsRepository);\n    using var tokenSource = new CancellationTokenSource();\n    var token = tokenSource.Token;\n\n    // Act\n    var exception = await Should.ThrowAsync&lt;NotFoundException&gt;(async () =&gt; await handler.Handle(command, token));\n\n    // Assert\n    exception.Message.ShouldBe(\"The Review with the supplied id was not found.\");\n    _ = await reviewsRepository.Received(1).UpdateReview(command.Id, command.Stars, command.Text, token);\n}\n</code></pre>\n<h2>Don't</h2>\n<ul>\n<li>Stop at the happy path.</li>\n<li>Put two behaviours in one test, or loop over unrelated cases in one <code>[Fact]</code>.</li>\n<li>Write a test with no assertion, or one that can't fail.</li>\n<li>Test only values in the middle of a range.</li>\n<li>Assert on log output or private state.</li>\n<li>Use random data where the value matters to the assertion. Pick it, or find a known row (<code>sample-data</code>).</li>\n</ul>\n<h2>Check</h2>\n<pre><code>dotnet test\n</code></pre>\n<p>Then read the test names for the class you changed. Each behaviour, success and failure, should have its own line.</p>\n","files":[{"path":"SKILL.md","sizeBytes":4547,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-11-27T19:10:38.09183Z","sha256":"477F56BB5DCEE3754FCBFE38D6668721C8D360B3B5DE1D3B8922E82F6585215C","sizeBytes":2176},"review":null,"source":{"repositoryUrl":"https://github.com/LeanMeanCleanApps/CleanGraphQLApi","path":".agents/skills/test-design","license":"MIT","commit":"1168fead2e0c8143a44bdce3344e0ab5fe1db90a","subtreeSha":"B6682DA3BA059737EBC9C08A59F4E1CF2067E9692CEAFD54B4B554E62481D346","lastSyncedAt":"2026-11-27T19:09:06.789278Z"},"reviewedAt":"2026-11-27T19:13:16.292624Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/LeanMeanCleanApps/CleanGraphQLApi/tree/main/.agents/skills/test-design"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install leanmeancleanapps-cleangraphqlapi@llmmart"},{"target":"git","command":"git clone https://github.com/LeanMeanCleanApps/CleanGraphQLApi.git"}]}