mcpField
M
mstest-skill

mstest-skill

github.com/lambdatestテスト・品質384202 回インストール2 週間前に更新
リポジトリ

mstest-skill について

mstest-skillは、MSTestで.NETコードをテストするためのリファレンススキルです。.NETのテスト開発者向けに、テストライフサイクル、データ駆動テスト、アサーション、統合テスト、テストデータ、ログ、CI/CDのパターンを扱います。

主な機能

  1. 01基本テストとデータ駆動テストのパターン
  2. 02アサーション、カテゴリ、タイムアウト
  3. 03テストとアセンブリのライフサイクルフック
  4. 04WebApplicationFactoryによるAPI統合テスト
  5. 05テストデータ、ログ、CI/CDのガイド

活用シーン

  1. 01.NETコードのパラメーター化テストの作成
  2. 02カテゴリとライフサイクルによるテスト整理
  3. 03インメモリデータベースを使ったAPI統合テストの構築

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/lambdatest/agent-skills --skill mstest-skill

インストール後、Claude Code で/mstest-skillを入力して読み込まれたか確認します。

同梱ファイルreference/advanced-patterns.mdreference/playbook.md

詳細

MSTest テストスキル

基本パターン

基本的なテスト
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class CalculatorTests
{
    private Calculator _calc;

    [TestInitialize]
    public void SetUp() => _calc = new Calculator();

    [TestMethod]
    public void Add_TwoNumbers_ReturnsSum()
    {
        Assert.AreEqual(5, _calc.Add(2, 3));
    }

    [TestMethod]
    [ExpectedException(typeof(DivideByZeroException))]
    public void Divide_ByZero_Throws()
    {
        _calc.Divide(10, 0);
    }
}
データ駆動テスト
[DataTestMethod]
[DataRow(2, 3, 5)]
[DataRow(-1, 1, 0)]
[DataRow(0, 0, 0)]
public void Add_Parameterized(int a, int b, int expected)
{
    Assert.AreEqual(expected, _calc.Add(a, b));
}

[DataTestMethod]
[DynamicData(nameof(GetTestData), DynamicDataSourceType.Method)]
public void Add_DynamicData(int a, int b, int expected)
{
    Assert.AreEqual(expected, _calc.Add(a, b));
}

private static IEnumerable<object[]> GetTestData()
{
    yield return new object[] { 1, 2, 3 };
    yield return new object[] { 10, -5, 5 };
}
アサーション
Assert.AreEqual(expected, actual);
Assert.AreNotEqual(unexpected, actual);
Assert.IsTrue(condition);
Assert.IsFalse(condition);
Assert.IsNull(obj);
Assert.IsNotNull(obj);
Assert.IsInstanceOfType(obj, typeof(MyClass));
Assert.ThrowsException<ArgumentException>(() => Method());
CollectionAssert.Contains(list, item);
CollectionAssert.AreEquivalent(expected, actual);
StringAssert.Contains(str, "substring");
StringAssert.StartsWith(str, "prefix");
StringAssert.Matches(str, new Regex(@"\d+"));
ライフサイクル
[AssemblyInitialize]  → Once per assembly (static)
[ClassInitialize]     → Once per class (static)
[TestInitialize]      → Before each test
[TestMethod]          → Test
[TestCleanup]         → After each test
[ClassCleanup]        → Once after class (static)
[AssemblyCleanup]     → Once after assembly (static)
カテゴリ
[TestMethod, TestCategory("Smoke")]
public void QuickTest() { }

[TestMethod, Ignore("Bug #456")]
public void SkippedTest() { }

[TestMethod, Timeout(5000)]
public void TimedTest() { }

セットアップ:dotnet add package MSTest.TestFramework MSTest.TestAdapter Microsoft.NET.Test.Sdk

実行:dotnet test または dotnet test --filter "TestCategory=Smoke"

高度なパターン

本番環境向けのパターンについては、reference/playbook.md を参照してください。

セクション内容
§1 プロジェクトのセットアップ.csproj の依存関係、並列実行とカバレッジ設定を含む .runsettings
§2 テストパターンTestMethod、DataTestMethod、DynamicData、例外テスト
§3 FluentAssertionsAssertionScope、非同期例外、コレクションのアサーション
§4 クラスとアセンブリの初期化Testcontainers、コストの高いセットアップの共有、グローバル設定
§5 WebApplicationFactoryインメモリ DB を使用した API 統合テスト
§6 Bogus テストデータ現実的なデータ生成のための Faker パターン
§7 TestContext とログ記録診断出力、カテゴリ、タイムアウト
§8 CI/CD 統合カバレッジレポートとしきい値を含む GitHub Actions
§9 デバッグ表よくある問題 12 件と原因および解決方法
§10 ベストプラクティス本番環境向けの 14 項目のチェックリスト

コメント