testing
БесплатноБез исполняемых скриптовНе проверенUse before planning or performing work that requires tests, and when writing, editing, refactoring, or debugging tests anywhere under `tests/**` (unit…
от 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}Testor{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
InProcessServerorCliHost, which fixtures and tests hold as members. - Test classes and fixtures MUST NOT implement
IDisposableorIAsyncDisposable. 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
IDisposableorIAsyncDisposable; 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(), runctx7 library AwesomeAssertions "<needed behavior>", then query the resolved ID withctx7 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"]!- useContainKey().WhoseValueinsteadHaveCount()+BeEquivalentTo()- redundant; equivalence checks count- Multiple assertions instead of
.Andchaining - LINQ before
Should()when an assertion-first equivalent exists. PreferContain,OnlyContain,AllSatisfy,HaveCount,ContainSingle().Which, and selector overloads for clearer failures. Use LINQ when no assertion API expresses the same outcome. - Replacing
All(predicate)withOnlyContain(predicate)without considering empty collections;OnlyContainfails when the collection is empty.
Utilities
IntegrationTestFixture: Core library integration testsCliIntegrationFixture: CLI integration with composition rootVerify.That<T>(): NSubstitute matcher with assertionsTestableLogger: Capture log messagesTestAnsiConsole: Console output verification- `Moc
Установить 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), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic