Agent Skills by ALSEL
OpenAIソフトウェア開発⭐ リポ 7品質スコア 74/100

xunit

xUnitフレームワークを使用して、30個のテストプロジェクト全体にわたるユニットテストを作成できます。以下のような場合にご利用ください:新しいテストの作成、テストカバレッジの追加、統合テストの作成、テストフィクスチャのセットアップ、またはテスト失敗のデバッグを行う際に使用します。

description の原文を見る

Writes unit tests with xUnit framework across 30 test projects. Use when: writing new tests, adding test coverage, creating integration tests, setting up test fixtures, or debugging test failures.

SKILL.md 本文

xUnit スキル

xUnit はテストフレームワークとして使用します。テストは読みやすいアサーションに Shouldly を、モッキングに Nsubstitute を使用します。すべてのテストは厳密な MethodName_Scenario_ExpectedBehavior ネーミングに従います。

クイックスタート

ユニットテスト構造

public class WalletManagerTests
{
    private readonly Mock<IRepository<Wallet>> _mockRepository;
    private readonly WalletManager _sut;

    public WalletManagerTests()
    {
        _mockRepository = new Mock<IRepository<Wallet>>();
        _sut = new WalletManager(_mockRepository.Object);
    }

    [Fact]
    public async Task CreateAsync_ValidWallet_ReturnsSuccess()
    {
        // Arrange
        var wallet = new Wallet { Name = "Test" };
        _mockRepository.Setup(r => r.AddAsync(wallet)).ReturnsAsync(wallet);

        // Act
        var result = await _sut.CreateAsync(wallet);

        // Assert
        result.IsSuccess.Should().BeTrue();
        result.Value.Should().Be(wallet);
    }
}

InlineData を使用したセオリー

[Theory]
[InlineData(12)]
[InlineData(15)]
[InlineData(18)]
[InlineData(21)]
[InlineData(24)]
public void GenerateMnemonic_ValidWordCount_ReturnsCorrectLength(int wordCount)
{
    var result = _keyManager.GenerateMnemonic(wordCount);

    result.IsSuccess.Should().BeTrue();
    result.Value!.Split(' ').Should().HaveCount(wordCount);
}

主要な概念

概念用途
[Fact]単一のテストケース[Fact] public void Method_Test() {}
[Theory]パラメータ化テスト[Theory] [InlineData(1)] public void Method(int x) {}
IClassFixture<T>クラス単位の共有状態class Tests : IClassFixture<DbFixture>
ICollectionFixture<T>クラス間の共有状態[Collection("Db")] class Tests
IAsyncLifetime非同期のセットアップ/ティアダウンTask InitializeAsync(), Task DisposeAsync()

一般的なパターン

例外テスト

[Fact]
public void Constructor_NullRepository_ThrowsArgumentNullException()
{
    var act = () => new WalletManager(null!);

    act.Should().Throw<ArgumentNullException>()
        .WithParameterName("repository");
}

[Fact]
public async Task ProcessAsync_InvalidData_ThrowsWithMessage()
{
    var exception = await Assert.ThrowsAsync<InvalidOperationException>(
        () => _processor.ProcessAsync(invalidContext));

    exception.Message.Should().Contain("validation failed");
}

非同期テストパターン

[Fact]
public async Task ExecuteAsync_ValidBlueprint_CompletesSuccessfully()
{
    // Arrange
    var blueprint = CreateTestBlueprint();

    // Act
    var result = await _engine.ExecuteAsync(blueprint);

    // Assert
    result.Success.Should().BeTrue();
    result.ProcessedData.Should().ContainKey("output");
}

関連項目

  • patterns - テストパターンとアンチパターン
  • workflows - テストワークフローとフィクスチャ

関連スキル

  • dotnet-testing-nsubstitute-mocking スキルを参照して、依存関係のモッキングについて確認してください
  • entity-framework スキルを参照して、InMemory プロバイダーを使用したデータベーステストについて確認してください

ドキュメンテーションリソース

Context7 で最新の xUnit ドキュメンテーションを取得します。

Context7 の使用方法:

  1. mcp__context7__resolve-library-id を使用して "xunit" を検索します
  2. 解決されたライブラリ ID を使用して mcp__context7__query-docs でクエリを実行します

ライブラリ ID: /xunit/xunit.net (875 個のコードスニペット、高評価)

推奨クエリ:

  • "xUnit Theory InlineData patterns"
  • "IClassFixture ICollectionFixture shared context"
  • "IAsyncLifetime async setup teardown"
  • "xUnit parallel test execution configuration"

ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ

詳細情報

作者
BridgingIT-GmbH
リポジトリ
BridgingIT-GmbH/bITdevKit
ライセンス
MIT
最終更新
2026/5/5

Source: https://github.com/BridgingIT-GmbH/bITdevKit / ライセンス: MIT

本サイトは GitHub 上で公開されているオープンソースの SKILL.md ファイルをクロール・インデックス化したものです。 各スキルの著作権は原作者に帰属します。掲載に問題がある場合は info@alsel.co.jp または /takedown フォームよりご連絡ください。
原作者: BridgingIT-GmbH · BridgingIT-GmbH/bITdevKit · ライセンス: MIT