writing-mstest-tests

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

Updated Aug 9, 2026
One-click install
npx skills add https://github.com/adinj00/player-performance --skill writing-mstest-tests-adinj00
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-mstest-tests
Source: https://github.com/adinj00/player-performance/tree/main/.agents/skills/writing-mstest-tests
Command: npx skills add https://github.com/adinj00/player-performance --skill writing-mstest-tests-adinj00

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing MSTest unit tests often leads to outdated patterns like [ExpectedException], generic Assert.IsTrue checks, swapped AreEqual arguments, and MSTESTxxxx analyzer warnings. This Skill guides you through writing, fixing, and modernizing MSTest 3.x/4.x tests with current APIs and best practices. ## Core Features & Use Cases - Modern assertion APIs: Replace Assert.IsTrue with specific assertions like IsEmpty, HasCount, Contains, IsInstanceOfType, and ThrowsExactly for clearer failure messages. - Data-driven and lifecycle patterns: Implement DataRow, DynamicData with ValueTuples, constructor-based initialization, TestContext injection, and cancellation token usage. - Analyzer fixes: Resolve MSTESTxxxx diagnostics with the idiomatic code fix for each rule. - Use Case: You inherit a test suite full of Assert.IsTrue(list.Count > 0) and [ExpectedException] attributes. Use this Skill to convert them to Assert.IsNotEmpty and Assert.ThrowsExactly, fix swapped AreEqual arguments, and clear all analyzer warnings. ## Quick Start Ask the AI to write MSTest unit tests for your C# class using modern MSTest 3.x assertions and data-driven patterns.

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 MSTest unit tests with modern assertions?

Use specific Assert methods instead of Assert.IsTrue: Assert.IsEmpty for empty collections, Assert.HasCount for counts, Assert.Contains for membership, and Assert.ThrowsExactly for exceptions. Follow the Arrange-Act-Assert pattern with [TestClass] and [TestMethod] attributes.

How to replace ExpectedException attribute in MSTest?

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

What is the correct argument order for Assert.AreEqual in MSTest?

Assert.AreEqual takes the expected value first and the actual value second: Assert.AreEqual(expected, actual). Swapped arguments trigger the MSTEST0017 analyzer diagnostic and produce confusing failure messages.

Does MSTest support data-driven tests with DynamicData?

Yes, MSTest supports [DataRow] for inline values and [DynamicData] for complex data. MSTest 3.7+ prefers ValueTuple return types over IEnumerable<object[]> for type safety, and TestDataRow<T> adds per-case metadata like DisplayName.

When should I not use this MSTest writing approach?

Do not use it for test quality audits or flaky-test investigations, running tests, or migrating between MSTest versions. It also does not apply to xUnit, NUnit, TUnit, or non-.NET languages.