writing-mstest-tests

Write and modernize MSTest 3.x/4.x unit tests using current assertion APIs and conventions.

1|Updated Jul 27, 2026
One-click install
npx skills add https://github.com/FittyAr/Cardscape --skill writing-mstest-tests-fittyar
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: writing-mstest-tests
Source: https://github.com/FittyAr/Cardscape/tree/main/.agents/skills/writing-mstest-tests
Command: npx skills add https://github.com/FittyAr/Cardscape --skill writing-mstest-tests-fittyar

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing MSTest unit tests often leads to outdated patterns like generic Assert.IsTrue checks, [ExpectedException] attributes, swapped AreEqual arguments, and legacy DynamicData formats, which produce poor failure messages and trigger MSTESTxxxx analyzer warnings. ## Core Features & Use Cases - Modern assertion guidance: Replace Assert.IsTrue with specific assertions like Assert.IsEmpty, HasCount, Contains, IsInstanceOfType, and ThrowsExactly for clearer failure messages. - Data-driven and lifecycle patterns: Implement DataRow, ValueTuple-based DynamicData, constructor injection of TestContext, and cooperative cancellation with TestContext.CancellationToken. - Analyzer diagnostics fixes: Map common MSTESTxxxx rules (e.g., MSTEST0006, MSTEST0017, MSTEST0037) to concrete code fixes. - Use Case: A developer inherits a test suite full of Assert.IsTrue(list.Count > 0) and [ExpectedException] attributes; this Skill rewrites them into Assert.IsNotEmpty and Assert.ThrowsExactly calls and resolves the resulting analyzer warnings. ## Quick Start Ask the AI to write MSTest unit tests for a given C# class or to modernize an existing MSTest test file using current assertion APIs.

Frequently Asked Questions about writing-mstest-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write data-driven tests in MSTest?▼

Use [DataRow] attributes for inline values on a [TestMethod], or [DynamicData] pointing to a property returning IEnumerable of ValueTuples for complex typed data. TestDataRow<T> lets you attach per-case DisplayName metadata.

What is the best MSTest assertion instead of Assert.IsTrue?▼

Use the most specific assertion: Assert.IsNotEmpty for non-empty collections, Assert.HasCount for exact counts, Assert.IsNull for null checks, and Assert.Contains for membership. Specific assertions produce clearer failure messages than generic boolean checks.

How do I replace ExpectedException in MSTest 3.x?▼

Replace [ExpectedException] with Assert.ThrowsExactly<T>(() => ...) for synchronous code or await Assert.ThrowsExactlyAsync<T> for async code. ThrowsExactly matches only the exact exception type, while Throws also matches derived types.

Does MSTest support parallel test execution?▼

Yes, add [assembly: Parallelize(Workers = 4, Scope = ExecutionScope.MethodLevel)] to enable method-level parallelization. Apply [DoNotParallelize] to specific test classes that share state, such as database integration tests.

How do I fix MSTEST0017 analyzer warnings?▼

MSTEST0017 indicates swapped Assert.AreEqual arguments. Put the expected value first and the actual value second, then rebuild to confirm the diagnostic is resolved.

When should I not use this MSTest writing approach?▼

Do not use it for test quality audits, running test suites, or version migrations from MSTest v1/v2 to v3 or v3 to v4. It also does not apply to xUnit, NUnit, TUnit, or non-.NET languages.