‹ 首页

mstest-skill

@lambdatest · 收录于 1 周前 · 上游提交 4 周前★ 社区精选

Generates MSTest tests in C#. Microsoft's built-in testing framework for .NET. Use when user mentions "MSTest", "[TestMethod]", "[TestClass]", "Assert.AreEqual". Triggers on: "MSTest", "[TestMethod]", "[TestClass]", "Microsoft test framework".

适合你,如果正在用 C# 写 .NET 项目,需要快速生成 MSTest 测试用例

/ 通过 npx 安装 校验哈希
npx oh-my-skill add lambdatest/agent-skills/mstest-skill
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- lambdatest/agent-skills/mstest-skill
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify lambdatest/agent-skills/mstest-skill
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
323GitHub stars
~691最小装载
~4.1K含声明引用
~4.6K文本包总量
索引托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · 54824d6

MSTest Testing Skill

Core Patterns
Basic Test
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);
    }
}
Data-Driven Tests
[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 };
}
Assertions
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+"));
Lifecycle
[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)
Categories
[TestMethod, TestCategory("Smoke")]
public void QuickTest() { }

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

[TestMethod, Timeout(5000)]
public void TimedTest() { }
Setup: dotnet add package MSTest.TestFramework MSTest.TestAdapter Microsoft.NET.Test.Sdk
Run: dotnet test or dotnet test --filter "TestCategory=Smoke"
Deep Patterns

See reference/playbook.md for production-grade patterns:

| Section | What You Get | |---------|-------------| | §1 Project Setup | .csproj deps, .runsettings with parallel + coverage config | | §2 Test Patterns | TestMethod, DataTestMethod, DynamicData, exception testing | | §3 FluentAssertions | AssertionScope, async exceptions, collection assertions | | §4 Class & Assembly Initialize | Testcontainers, shared expensive setup, global config | | §5 WebApplicationFactory | API integration tests with in-memory DB | | §6 Bogus Test Data | Faker patterns for realistic data generation | | §7 TestContext & Logging | Diagnostic output, categories, timeouts | | §8 CI/CD Integration | GitHub Actions with coverage reporting and thresholds | | §9 Debugging Table | 12 common problems with causes and fixes | | §10 Best Practices | 14-item production checklist |

按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。