agentleFS
fpindejfpindej/netrock/.claude/skills/add-test/SKILL.md

add-test

Skill234 starsChanged 3 months agoMITView on GitHub

Add tests following project test patterns

18 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use triage and 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.
  • Google CloudSkill

    triage

    Gather context on a change or bug and plan the implementation.

    Also in 3 projects that use this

  • SentrySkill

    review

    Fixture review skill.

    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, 2 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No mocking, no DI - test pure inputs and outputs

    line 15
  2. Distinctive:

    Create mocks in constructor:

    line 23
  3. Very specific:

    If service interface not mocked in CustomWebApplicationFactory, add it there first

    line 58
  4. Very specific:

    Use TestValidate + assertion helpers:

    line 67
  5. Very specific:

    Create src/frontend/src/lib/{module}/{file}.test.ts (co-located with source)

    line 96
  6. Very specific:

    Default environment is node.

    line 98
  7. Very specific:

    Add // @vitest-environment jsdom at top of file

    line 107

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

Adds tests. Specify test type or infer from context.

Unit Test

For pure logic in Shared, Domain, or Application layers.

  1. Create src/backend/tests/MyProject.Unit.Tests/{Layer}/{ClassUnderTest}Tests.cs
  2. Structure: {Method}_{Scenario}_{Expected} naming
  3. No mocking, no DI - test pure inputs and outputs
  4. Verify: dotnet test src/backend/tests/MyProject.Unit.Tests -c Release

Component Test

For service business logic with mocked dependencies.

  1. Create src/backend/tests/MyProject.Component.Tests/Services/{Service}Tests.cs
  2. Create mocks in constructor:
    private readonly MyProjectDbContext _dbContext = TestDbContextFactory.Create();
    private readonly IOrderRepository _orderRepo = Substitute.For<IOrderRepository>();
    private readonly HybridCache _cache = Substitute.For<HybridCache>();
  3. For Identity: IdentityMockHelpers.CreateMockUserManager() / CreateMockRoleManager()
  4. Assert on Result: Assert.True(result.IsSuccess); Assert.Equal(expectedId, result.Value);
  5. Verify: dotnet test src/backend/tests/MyProject.Component.Tests -c Release

API Integration Test

For testing the full HTTP pipeline (routes, auth, validation, status codes).

  1. Create src/backend/tests/MyProject.Api.Tests/Controllers/{Controller}Tests.cs
  2. Structure:
    public class OrdersControllerTests : IClassFixture<CustomWebApplicationFactory>, IDisposable
    {
        private readonly CustomWebApplicationFactory _factory;
        private readonly HttpClient _client;
        public OrdersControllerTests(CustomWebApplicationFactory factory)
        {
            _factory = factory;
            _client = factory.CreateClient();
        }
        public void Dispose() => _client.Dispose();
    }
  3. Auth per-request via Authorization header:
    • "Test" - basic authenticated user
    • TestAuth.WithPermissions(AppPermissions.Users.View) - specific permissions
    • TestAuth.Superuser() - bypasses all checks
    • No header - unauthenticated (401)
  4. Configure mock returns: _factory.AdminService.Method(...).Returns(...);
  5. If service interface not mocked in CustomWebApplicationFactory, add it there first
  6. For 200/201 responses, add response contract assertions using frozen records in Contracts/ResponseContracts.cs
  7. Verify: dotnet test src/backend/tests/MyProject.Api.Tests -c Release

Validator Test

For FluentValidation rules without starting the test server.

  1. Create src/backend/tests/MyProject.Api.Tests/Validators/{Validator}Tests.cs
  2. Use TestValidate + assertion helpers:
    using FluentValidation.TestHelper;
    
    public class OrderRequestValidatorTests
    {
        private readonly OrderRequestValidator _validator = new();
    
        [Fact]
        public void ValidRequest_ShouldPassValidation()
        {
            var result = _validator.TestValidate(new OrderRequest { Name = "Widget", Quantity = 1 });
            result.ShouldNotHaveAnyValidationErrors();
        }
    
        [Fact]
        public void MissingName_ShouldFail()
        {
            var result = _validator.TestValidate(new OrderRequest { Name = "", Quantity = 1 });
            result.ShouldHaveValidationErrorFor(x => x.Name);
        }
    }
  3. Verify: dotnet test src/backend/tests/MyProject.Api.Tests -c Release

Frontend Unit Test

For utility functions, state modules, and pure logic in $lib/.

  1. Create src/frontend/src/lib/{module}/{file}.test.ts (co-located with source)
  2. Import explicitly: import { describe, it, expect, vi } from 'vitest'
  3. Default environment is node. For DOM tests, add // @vitest-environment jsdom at top of file
  4. restoreMocks: true is configured globally - no manual cleanup needed
  5. Verify: cd src/frontend && pnpm run test

Frontend Component Test

For Svelte components with DOM interactions.

  1. Create src/frontend/src/lib/components/{feature}/{Component}.test.ts (co-located)
  2. Add // @vitest-environment jsdom at top of file
  3. Mock SvelteKit modules as needed:
    vi.mock('$app/navigation', () => ({ goto: vi.fn(), invalidateAll: vi.fn() }));
    vi.mock('$lib/paraglide/messages', () => new Proxy({}, { get: (_, key) => () => String(key) }));
  4. Verify: cd src/frontend && pnpm run test

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.