writing-mstest-tests

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

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/D1ssolve/craft-agents --skill writing-mstest-tests-d1ssolve
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-mstest-tests
Source: https://github.com/D1ssolve/craft-agents/tree/main/skills/writing-mstest-tests
Command: npx skills add https://github.com/D1ssolve/craft-agents --skill writing-mstest-tests-d1ssolve

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing MSTest unit tests with outdated patterns leads to poor failure messages, fragile assertions, and inconsistent test structure. This Skill guides you through writing new MSTest tests and fixing existing ones using modern MSTest 3.x/4.x APIs and best practices. ## Core Features & Use Cases - Modern assertion APIs: Replace generic Assert.IsTrue with specific assertions like Assert.IsEmpty, Assert.HasCount, Assert.Contains, Assert.IsInstanceOfType, and Assert.ThrowsExactly for clearer failure messages. - Data-driven tests: Build parameterized tests with DataRow, DynamicData with ValueTuples, and TestDataRow metadata for type-safe test data. - Lifecycle and advanced patterns: Apply constructor-based initialization, TestContext injection, cancellation tokens with timeouts, retry, conditional execution, and parallelization. - Use Case: You have a test using Assert.IsTrue(list.Count == 3) and a hard cast on a result object. This Skill rewrites it as Assert.HasCount(3, list) and Assert.IsInstanceOfType<MyHandler>(result), and fixes swapped Assert.AreEqual argument order. ## Quick Start Ask the assistant to write MSTest unit tests for your C# class or to modernize the assertions in your existing MSTest test file.

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 in C#?

Create a sealed class marked with [TestClass] and methods marked with [TestMethod], following the Arrange-Act-Assert pattern. Use MSTest.Sdk or the MSTest metapackage in your project, and name tests as MethodName_Scenario_ExpectedBehavior.

What should I use instead of Assert.IsTrue in MSTest?

Replace Assert.IsTrue with specific assertions that produce better failure messages: Assert.IsNotEmpty for non-empty collections, Assert.HasCount for exact counts, Assert.IsNull or IsNotNull for null checks, and Assert.Contains for collection membership.

How do I test exceptions in MSTest without ExpectedException?

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

Does MSTest support data-driven tests with multiple inputs?

Yes, use [DataRow] for inline values and [DynamicData] for complex data. MSTest 3.7+ supports ValueTuple return types for DynamicData, which is preferred over IEnumerable<object[]> for type safety.

When should I not use this MSTest writing skill?

Do not use it for test quality audits (use test-anti-patterns), running tests (use run-tests), MSTest version migrations, or projects using xUnit, NUnit, or TUnit frameworks.