From qa-unit-tests-net
Configures and runs MSTest (now MSTest.TestFramework v3) - Microsoft's first-party .NET test framework with `[TestClass]` / `[TestMethod]` / `[DataRow]` / `[DynamicData]` attributes; `[ClassInitialize]` / `[ClassCleanup]` / `[TestInitialize]` / `[TestCleanup]` lifecycle; `TestContext` injection; tight Visual Studio + dotnet test integration. Use when working with .NET on a MSTest codebase, or in environments standardized on Microsoft toolchain.
How this skill is triggered — by the user, by Claude, or both
Slash command
/qa-unit-tests-net:mstest-testsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Per [learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest][ms-doc]:
Per learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest:
For new code, xunit-tests or
nunit-tests are more mainstream.
MSTest is the right pick for Microsoft-mandated environments + legacy.
dotnet new mstest -n MyTests
# Or in existing project:
dotnet add package MSTest.TestFramework
dotnet add package MSTest.TestAdapter
dotnet add package Microsoft.NET.Test.Sdk
Per ms-doc:
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class CalculatorTests
{
[TestMethod]
public void Adds_TwoNumbers()
{
Assert.AreEqual(3, Calculator.Add(1, 2));
}
}
Note: Assert.AreEqual(expected, actual) argument order matches
NUnit, NOT xUnit's (expected, actual) order.
Run: dotnet test.
Per ms-doc:
[TestClass]
public class TestsWithLifecycle
{
[ClassInitialize]
public static void ClassInit(TestContext context) { /* once before all */ }
[ClassCleanup]
public static void ClassCleanup() { /* once after all */ }
[TestInitialize]
public void TestInit() { /* before each test */ }
[TestCleanup]
public void TestCleanup() { /* after each test */ }
[TestMethod]
public void Test1() { ... }
}
For assembly-level: [AssemblyInitialize] + [AssemblyCleanup].
[TestMethod]
[DataRow(1, 2, 3)]
[DataRow(0, 0, 0)]
[DataRow(-1, 1, 0)]
public void Adds_VariousInputs(int a, int b, int expected)
{
Assert.AreEqual(expected, Calculator.Add(a, b));
}
// Dynamic data source
[TestMethod]
[DynamicData(nameof(AddCases), DynamicDataSourceType.Method)]
public void Adds_FromDynamic(int a, int b, int expected) { ... }
public static IEnumerable<object[]> AddCases()
{
yield return new object[] { 1, 2, 3 };
yield return new object[] { 0, 0, 0 };
}
[TestMethod]
[TestCategory("Integration")]
public void IntegrationTest() { }
// Filter: dotnet test --filter "TestCategory=Integration"
TestContext is auto-injected per test instance:
[TestClass]
public class TestsWithContext
{
public TestContext TestContext { get; set; } // auto-populated by runner
[TestMethod]
public void LogsContext()
{
TestContext.WriteLine("Test name: {0}", TestContext.TestName);
}
}
TestContext provides per-test metadata (test name, deployment dir,
properties from .runsettings) + a WriteLine for output (similar to
xUnit's ITestOutputHelper).
[TestMethod]
[Ignore("Requires staging DB; tracked in JIRA-1234")]
public void Skipped() { }
// Conditional skip via runtime check
[TestMethod]
public void ConditionalTest()
{
if (!IsRunningOnLinux) Assert.Inconclusive("Linux-only test");
// ...
}
Assert.Inconclusive marks the test as neither pass nor fail
(distinct from skip).
.runsettings:
<RunSettings>
<RunConfiguration>
<MaxCpuCount>4</MaxCpuCount>
</RunConfiguration>
<MSTest>
<Parallelize>
<Workers>4</Workers>
<Scope>MethodLevel</Scope>
</Parallelize>
</MSTest>
</RunSettings>
Scope: MethodLevel (parallel within class) or ClassLevel
(parallel across classes only).
- run: dotnet test --logger "trx;LogFileName=test-results.trx" \
--collect:"XPlat Code Coverage" \
--settings test.runsettings
| Anti-pattern | Why it fails | Fix |
|---|---|---|
Argument order: Assert.AreEqual(actual, expected) (xUnit-style) | MSTest is (expected, actual); failure messages reversed | Verify order (Step 2) |
Skip [TestClass] annotation | Discovery fails (unlike NUnit which auto-discovers) | Always include [TestClass] |
Use Console.WriteLine instead of TestContext.WriteLine | Output may not appear in test runner | Use TestContext (Step 6) |
Assert.Inconclusive overuse | Tests neither pass nor fail; signals lost | Use [Ignore] for permanent skips (Step 7) |
Assert.AreEqual ordering different from xUnit (migration source
of bugs).[MemberData].xunit-tests,
nunit-tests,
fluentassertions - sister toolstest-code-conventionsnpx claudepluginhub testland/qa --plugin qa-unit-tests-netProvides CDSS development patterns for drug interaction checking, dose validation, clinical scoring (NEWS2, qSOFA), and alert classification integrated into EMR workflows.