mstest-skill

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".

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "mstest-skill" with this command: npx skills add lambdatest/agent-skills/lambdatest-agent-skills-mstest-skill

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:

SectionWhat You Get
§1 Project Setup.csproj deps, .runsettings with parallel + coverage config
§2 Test PatternsTestMethod, DataTestMethod, DynamicData, exception testing
§3 FluentAssertionsAssertionScope, async exceptions, collection assertions
§4 Class & Assembly InitializeTestcontainers, shared expensive setup, global config
§5 WebApplicationFactoryAPI integration tests with in-memory DB
§6 Bogus Test DataFaker patterns for realistic data generation
§7 TestContext & LoggingDiagnostic output, categories, timeouts
§8 CI/CD IntegrationGitHub Actions with coverage reporting and thresholds
§9 Debugging Table12 common problems with causes and fixes
§10 Best Practices14-item production checklist

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

appium-skill

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

selenium-skill

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

playwright-skill

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

jasmine-skill

No summary provided by upstream source.

Repository SourceNeeds Review