agentleFS
LeanMeanCleanAppsLeanMeanCleanApps/CleanModelContextProtocol/.agents/skills/test-design/SKILL.md

test-design

Skill1 starsChanged 6 days agoMITView on GitHub

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.

18 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use diff-review.

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.
  • MidnightDarlingSkill

    diff-review

    使用场景:按 raw.review.md 清单改完稿后,对 raw.md(OCR 原始)和 final.md(定稿)做对比。说"看我改了哪些""对比一下""diff""校对完了让我看看""我到底接受了哪些建议""我漏改了啥""改动统计""核对一下改动""闭环检查"都走这个 skill。生成段落级 HTML diff,关联 raw.review.md 的 A/B/C 标注,一目了然:接受了哪些 agent 建议、拒绝了哪些、清单外修正了哪些、agent 标过但漏改了哪些。主动触发,不必等用户说 "diff-review"。

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 12 edited versions we read keep these.

  • 3

    Distinctive

    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
  1. Very specific:

    Every test has // Arrange, // Act and // Assert sections, tests one behaviour, and is named Method_Should<Outcome>_<Condition> so a failure …

    line 14
  2. Very specific:

    Run the coverage command (coverage) last, to find behaviour you forgot, not to pick lines to cover.

    line 34
  3. Distinctive:

    Stop at the happy path.

    line 73
  4. Very specific:

    Put two behaviours in one test, or loop over unrelated cases in one [Fact].

    line 74
  5. Distinctive:

    Write a test with no assertion, or one that can't fail.

    line 75
  6. Distinctive:

    Test only values in the middle of a range.

    line 76
  7. Very specific:

    Use random data where the value matters to the assertion.

    line 78

“Common” is measured: kept by at least 6 in 10 of the 12 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Test design

The rule

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.

Every test has // Arrange, // Act and // Assert sections, tests one behaviour, and is named Method_Should<Outcome>_<Condition> so a failure reads as a sentence.

What each kind of code needs:

CodePositive casesNegative cases
ValidatorA valid request has no errors; each allowed boundary value passesOne failing case per rule, asserting the message; each value just outside a boundary fails
HandlerThe happy path returns the expected result and passes the request's values and the token to the repositoryEach documented failure (not found, conflict) throws the right exception, and later calls don't happen
RepositoryThe right rows come back or change, in the right order, with paging and search appliedUnknown ids return null or false; nothing else changes
Endpoint, tool, resolver or functionOne test per documented success statusOne test per documented failure status (validation problem, not found, unauthorised) with the problem body checked
Behaviour or middlewareIt calls the next step and passes the result throughIt stops the request when it should, and the next step isn't called

Steps

  1. 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.
  2. For each range or limit, test both sides: the last value allowed and the first value refused (stars 1 and 5 pass, 0 and 6 fail; limit 50 passes, 51 fails). Use a [Theory] with [InlineData] for each side.
  3. 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.
  4. Assert that the cancellation token reaches every repository call (cancellation).
  5. On a negative path, assert that the work after the failure didn't happen (DidNotReceiveWithAnyArgs()).
  6. Fixing a bug? Write the test that shows it first, watch it fail, then fix the code.
  7. Run the coverage command (coverage) last, to find behaviour you forgot, not to pick lines to cover.

Example

// tests/Application.Tests.Unit/Reviews/Commands/CreateReview/CreateReviewValidatorTests.cs
[Theory]
[InlineData(-1)]
[InlineData(0)]
[InlineData(6)]
[InlineData(100)]
[InlineData(-100)]
public void Validator_ShouldHaveValidationErrorFor_Stars(int stars)
// tests/Application.Tests.Unit/Reviews/Commands/UpdateReview/UpdateReviewHandlerTests.cs
[Fact]
public async Task Handle_ShouldThrowException_ReviewDoesNotExist()
{
    // Arrange
    var command = new UpdateReviewCommand { Id = Guid.NewGuid(), Stars = 5 };
    var reviewsRepository = Substitute.For<IReviewsRepository>();
    _ = reviewsRepository.UpdateReview(default, default, default).ReturnsForAnyArgs((Review?)null);
    var handler = new UpdateReviewHandler(reviewsRepository);
    using var tokenSource = new CancellationTokenSource();
    var token = tokenSource.Token;

    // Act
    var exception = await Should.ThrowAsync<NotFoundException>(async () => await handler.Handle(command, token));

    // Assert
    exception.Message.ShouldBe("The Review with the supplied id was not found.");
    _ = await reviewsRepository.Received(1).UpdateReview(command.Id, command.Stars, command.Text, token);
}

Don't

  • Stop at the happy path.
  • Put two behaviours in one test, or loop over unrelated cases in one [Fact].
  • Write a test with no assertion, or one that can't fail.
  • Test only values in the middle of a range.
  • Assert on log output or private state.
  • Use random data where the value matters to the assertion. Pick it, or find a known row (sample-data).

Check

dotnet test

Then read the test names for the class you changed. Each behaviour, success and failure, should have its own line.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.