csharp-mstest

Write MSTest 3.x/4.x unit tests using modern assertion APIs and data-driven test patterns.

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill csharp-mstest-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-mstest
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/csharp-mstest
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill csharp-mstest-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing C# unit tests with outdated MSTest patterns leads to unclear failure messages, obsolete APIs like [ExpectedException], and missed opportunities for type-safe data-driven testing. This Skill provides current MSTest 3.x/4.x best practices so tests are maintainable and expressive. ## Core Features & Use Cases - Modern Assertion APIs: Covers Assert.Throws, Assert.ThrowsExactly, collection assertions, comparison assertions, and the MSTest 4.0 Assert.That API with correct argument ordering. - Data-Driven Tests: Guides DataRow and DynamicData usage, preferring type-safe ValueTuple and TestDataRow sources over IEnumerable<object[]>. - Lifecycle and TestContext: Documents execution order, constructor-based setup, TestContext injection, cancellation tokens, retries, conditional execution, and parallelization. - Use Case: When adding tests to a C# service class, apply the AAA pattern, seal test classes, use Assert.ThrowsExactly for exception checks, and parameterize edge cases with DynamicData ValueTuple sources. ## Quick Start Write MSTest unit tests for my Calculator class using modern assertion APIs and data-driven test cases.

Frequently Asked Questions about csharp-mstest

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 or [DynamicData] with a static data source for complex cases. Prefer IEnumerable of ValueTuple or TestDataRow over IEnumerable<object[]> for compile-time type safety and custom display names.

How to assert exceptions in MSTest without ExpectedException?

Use Assert.Throws<TException> to match an exception type or its derived types, or Assert.ThrowsExactly<TException> for exact type matching. Async variants Assert.ThrowsAsync and Assert.ThrowsExactlyAsync handle async methods.

What is the difference between MSTest 3.x and 4.x assertion APIs?

MSTest 4.x adds Assert.That for expression-capturing assertions and changes Assert.IsInstanceOfType<T> to return the typed result directly instead of using an out parameter. Core Assert, StringAssert, and CollectionAssert APIs remain consistent.

Should I use TestInitialize or a constructor in MSTest?

Prefer constructors over [TestInitialize] because they enable readonly fields and follow standard C# patterns. Combine a constructor with an async [TestInitialize] method only when asynchronous setup is required.

How do I run MSTest tests only on specific operating systems?

Apply [OSCondition] with OperatingSystems flags like Windows, Linux, or MacOS, using ConditionMode.Exclude to skip platforms. [CICondition] similarly restricts tests to CI environments or local runs. These attributes require MSTest 3.10 or later.