Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

testing

БесплатноБез исполняемых скриптовНе проверен

Use before planning or performing work that requires tests, and when writing, editing, refactoring, or debugging tests anywhere under `tests/**` (unit…

recyclarrот recyclarr★ 2 180 звёзд на GitHub

Об этом скилле

Testing Patterns and Infrastructure

Technical Stack

  • TUnit test framework, run by Microsoft.Testing.Platform (global.json); its assertions are not used
  • NSubstitute for mocking
  • AwesomeAssertions for fluent assertions (NOT FluentAssertions)

Test Pyramid

  • E2E: Critical user workflows against real services (Testcontainers)
  • Integration: Complete workflows with mocked externals (Git, HTTP, filesystem)
  • Unit: Edge cases integration cannot reach

Cover each code path once, at the highest level that reaches it. MUST NOT add a unit test for a path an integration test already exercises. Add one only after scripts/coverage.py shows lines the integration tests leave uncovered (see Coverage Analysis).

Naming

  • Classes: {Component}Test or {Component}IntegrationTest
  • Methods: Underscore-separated behavior (Load_many_iterations_of_config)
  • Pattern: internal sealed class

Integration Test Setup

internal sealed class MyFeatureIntegrationTest : CliIntegrationFixture
{
    protected override void RegisterStubsAndMocks(ContainerBuilder builder)
    {
        // Register custom mocks here
    }
}

Mock externals only: Git (LibGit2Sharp), HTTP APIs, filesystem (MockFileSystem).

Unit Test Setup

Construct the class under test explicitly. Declare doubles the tests configure or assert on as field initializers (private readonly MockFileSystem _fs = new();) and build the class under test in a CreateSut() helper. TUnit creates a new test class instance for every test, so each test gets fresh fields.

Parameterized tests need [Test] plus one [Arguments(...)] per case; data sources use [MethodDataSource]. Per-test setup and teardown use [Before(Test)] and [After(Test)].

Fixtures, Helpers, and Cleanup

  • A fixture is only ever the base class of test classes; MUST NOT construct one directly. Setup that code creates and disposes itself (an in-process server, a composition root) belongs in a plain helper type such as InProcessServer or CliHost, which fixtures and tests hold as members.
  • Test classes and fixtures MUST NOT implement IDisposable or IAsyncDisposable. Dispose owned fields in an [After(Test)] method: TUnit runs a derived class's hooks before its base's and runs every hook even when one throws.
  • Helpers implement IDisposable or IAsyncDisposable; their owner disposes them.
  • A test class or fixture that owns a disposable field triggers CA1001. Suppress it with [SuppressMessage] on that class, justified by the [After(Test)] hook that disposes the field (TUnit0023 enforces the hook). This is the only allowed exception: never suppress CA1001 on helpers, or CA2213 and TUnit0023 anywhere.

NSubstitute Patterns

Arrange (setting up dependencies):

dependency.Method().Returns(value);
dependency.Property.ReturnsNull();
dependency.Method(default!).ReturnsForAnyArgs(value);
dependency.Method().Returns([item1, item2]);
Verify.That<T>(x => x.Property.Should().Be(expected));

Argument matching (returns setup and received verification): Prefer ReceivedWithAnyArgs()/ReturnsForAnyArgs() with default over Arg.Any<T>():

// Good
mock.ReceivedWithAnyArgs().SetStatus(default, default);
mock.Method(default!, default!).ReturnsForAnyArgs(value);

// Bad
mock.Received().SetStatus(Arg.Any<Status>(), Arg.Any<int?>());
mock.Method(Arg.Any<string>(), Arg.Any<int>()).ReturnsForAnyArgs(value);

AwesomeAssertions

  • Before writing an unfamiliar assertion or using LINQ to shape the value passed to Should(), run ctx7 library AwesomeAssertions "<needed behavior>", then query the resolved ID with ctx7 docs. Check for a direct assertion, selector overload, or chaining API first.

Preferred:

result.Should().BeEquivalentTo(expected);
collection.Should().AllSatisfy(x => x.Property.Should().Be(expected));
act.Should().Throw<ExceptionType>().WithMessage("pattern");
collection.Should().HaveCount(n).And.Contain(item);
dict.Should().ContainKey(key).WhoseValue.Should().Be(expected);

Anti-patterns:

  • dict!["key"]! - use ContainKey().WhoseValue instead
  • HaveCount() + BeEquivalentTo() - redundant; equivalence checks count
  • Multiple assertions instead of .And chaining
  • LINQ before Should() when an assertion-first equivalent exists. Prefer Contain, OnlyContain, AllSatisfy, HaveCount, ContainSingle().Which, and selector overloads for clearer failures. Use LINQ when no assertion API expresses the same outcome.
  • Replacing All(predicate) with OnlyContain(predicate) without considering empty collections; OnlyContain fails when the collection is empty.

Utilities

  • IntegrationTestFixture: Core library integration tests
  • CliIntegrationFixture: CLI integration with composition root
  • Verify.That<T>(): NSubstitute matcher with assertions
  • TestableLogger: Capture log messages
  • TestAnsiConsole: Console output verification
  • `Moc
Полный SKILL.md на GitHub

Установить testing в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл testing?

Use before planning or performing work that requires tests, and when writing, editing, refactoring, or debugging tests anywhere under `tests/**` (unit, integration, or end-to-end); authoring TUnit test classes (`*Test`, `*IntegrationTest`); using NSubstitute mocks or AwesomeAssertions (NOT FluentAssertions); working with `CliIntegrationFixture`, `IntegrationTestFixture`, `MockFileSystem`, `TestableLogger`, `TestAnsiConsole`, or `New*` factory helpers; adding or updating E2E fixtures under `tests/Recyclarr.EndToEndTests/Fixtures/` (`recyclarr.yml`, `settings.yml`, `custom-formats-*`, `trash-guides-override/`); running `run-e2e-tests.sh` or `scripts/coverage.py`; running the pre-completion smoke test; investigating flaky tests, coverage gaps, or Testcontainers setup. Triggers on phrases like "write a test", "fix this test", "improve coverage", "add an E2E case", "mock this dependency", or any edit to `*.Tests.csproj` or files under `tests/**`.

Как установить скилл testing?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл testing запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить testing с