csharp-mstest

Guides writing and refactoring MSTest 3.x/4.x unit tests with modern assertion APIs.

Updated Aug 24, 2026
One-click install
npx skills add https://github.com/aggutierrez98/TP-TD --skill csharp-mstest-aggutierrez98
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: csharp-mstest
Source: https://github.com/aggutierrez98/TP-TD/tree/main/.agents/skills/csharp-mstest
Command: npx skills add https://github.com/aggutierrez98/TP-TD --skill csharp-mstest-aggutierrez98

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing C# unit tests with MSTest often leads to outdated patterns like [ExpectedException], wrong Assert argument order, and untyped test data. This Skill provides current MSTest 3.x/4.x best practices so tests are correct, maintainable, and use modern APIs. ## Core Features & Use Cases - Modern Assertion Guidance: Covers Assert.Throws, Assert.ThrowsExactly, collection, string, comparison, and type assertions, plus Assert.That in MSTest 4.0. - Data-Driven Test Patterns: Explains DataRow, DynamicData with ValueTuple and TestDataRow for type-safe parameterized tests. - Lifecycle and Advanced Features: Details execution order, TestContext usage, cancellation tokens, retry, OS/CI conditional execution, parallelization, and work item traceability. - Use Case: When refactoring a legacy test suite that uses [ExpectedException] and IEnumerable<object[]> data sources, apply this Skill to migrate to Assert.ThrowsExactly and type-safe ValueTuple DynamicData. ## Quick Start Review my MSTest test class and refactor it to follow modern MSTest 3.x best practices.

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 property returning IEnumerable of ValueTuple or TestDataRow for type-safe data sources. Prefer ValueTuple over IEnumerable<object[]> since object arrays provide no compile-time type checking.

How to test exceptions in MSTest without ExpectedException?▼

Use Assert.Throws<TException> to verify an exception of the type or derived types is thrown, or Assert.ThrowsExactly<TException> for exact type matching. Async variants Assert.ThrowsAsync and Assert.ThrowsExactlyAsync handle async methods.

Should I use constructor or TestInitialize 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.

Does MSTest support parallel test execution?▼

Yes, apply [assembly: Parallelize(Workers = 4, Scope = ExecutionScope.MethodLevel)] at the assembly level to run tests in parallel. Use [DoNotParallelize] on specific test classes that must run sequentially.

What is the correct argument order for Assert.AreEqual?▼

Assert.AreEqual takes the expected value first, then the actual value: Assert.AreEqual(expected, actual). Reversing the order produces confusing failure messages that misreport which value was expected.