Skip to main content

Build

Dotnet Test Frameworks

.NETOfficialCertified

Reference data for .NET test framework detection patterns, assertion APIs, skip annotations, setup/teardown methods, and common test smell indicators across MSTest, xUnit, NUnit, and TUnit. Loaded by test analysis skills (test-anti-patterns) as framework-specific lookup tables.

  • New
  • v1.0.0
  • Reviewed Jul 21
  • No reviews yet

Getting started

Full instructions

Install the skill, then ask your AI tool for the task in plain words. The full SKILL.md below shows what it covers.

Instructions: SKILL.mdv1.0.0

.NET Test Framework Reference

Language-specific detection patterns for .NET test frameworks (MSTest, xUnit, NUnit, TUnit).

Test File Identification

Framework Test class markers Test method markers
MSTest [TestClass] [TestMethod], [DataTestMethod]
xUnit (none — convention-based) [Fact], [Theory]
NUnit [TestFixture] [Test], [TestCase], [TestCaseSource]
TUnit (none — convention-based) [Test]

Assertion APIs by Framework

Category MSTest xUnit NUnit TUnit
Equality Assert.AreEqual Assert.Equal Assert.That(x, Is.EqualTo(y)) await Assert.That(x).IsEqualTo(y)
Boolean Assert.IsTrue / Assert.IsFalse Assert.True / Assert.False Assert.That(x, Is.True) await Assert.That(x).IsTrue() / await Assert.That(x).IsFalse()
Null Assert.IsNull / Assert.IsNotNull Assert.Null / Assert.NotNull Assert.That(x, Is.Null) await Assert.That(x).IsNull() / await Assert.That(x).IsNotNull()
Exception Assert.Throws<T>() / Assert.ThrowsExactly<T>() Assert.Throws<T>() Assert.That(() => ..., Throws.TypeOf<T>()) await Assert.That(() => ...).Throws<T>() / await Assert.That(() => ...).ThrowsExactly<T>()
Collection CollectionAssert.Contains Assert.Contains Assert.That(col, Has.Member(x)) await Assert.That(col).Contains(x)
String StringAssert.Contains Assert.Contains(str, sub) Assert.That(str, Does.Contain(sub)) await Assert.That(str).Contains(sub)
Type Assert.IsInstanceOfType Assert.IsAssignableFrom Assert.That(x, Is.InstanceOf<T>()) await Assert.That(x).IsAssignableTo<T>() (use await Assert.That(x).IsTypeOf<T>() for exact-type check)
Inconclusive Assert.Inconclusive() skip via [Fact(Skip)] Assert.Inconclusive() Skip.Test("reason") (no true inconclusive state)
Fail Assert.Fail() Assert.Fail() (.NET 10+) Assert.Fail() Assert.Fail()

TUnit-specific: assertions are async and must be awaited — a forgotten await causes the assertion to never run, and the test passes silently. A built-in analyzer warns when await is missing. Multiple assertions can be combined with .And / .Or chaining or grouped via Assert.Multiple().

Third-party assertion libraries: Should* (Shouldly), .Should() (FluentAssertions / AwesomeAssertions), Verify() (Verify). TUnit also ships an optional TUnit.Assertions.Should package providing FluentAssertions-style value.Should().BeEqualTo(...) on top of the same infrastructure.

Sleep/Delay Patterns

Pattern Example
Thread sleep Thread.Sleep(2000)
Task delay await Task.Delay(1000)
SpinWait SpinWait.SpinUntil(() => condition, timeout)

Skip/Ignore Annotations

Framework Annotation With reason
MSTest [Ignore] [Ignore("reason")]
xUnit [Fact(Skip = "reason")] (reason is required)
NUnit [Ignore("reason")] (reason is required)
TUnit [Skip("reason")] (reason is required; also valid at class and assembly scope, e.g. [assembly: Skip("…")]. Dynamic in-test skipping via Skip.Test("reason").)
Conditional #if false / #if NEVER (no reason possible)

Exception Handling — Idiomatic Alternatives

When a test uses try/catch to verify exceptions, suggest the framework-native alternative:

MSTest:

csharp
// Instead of try/catch (matches exact type):
var ex = Assert.ThrowsExactly<InvalidOperationException>(
    () => processor.ProcessOrder(emptyOrder));
Assert.AreEqual("Order must contain at least one item", ex.Message);

// Or (also matches derived types):
var ex = Assert.Throws<InvalidOperationException>(
    () => processor.ProcessOrder(emptyOrder));
Assert.AreEqual("Order must contain at least one item", ex.Message);

xUnit:

csharp
var ex = Assert.Throws<InvalidOperationException>(
    () => processor.ProcessOrder(emptyOrder));
Assert.Equal("Order must contain at least one item", ex.Message);

NUnit:

csharp
var ex = Assert.Throws<InvalidOperationException>(
    () => processor.ProcessOrder(emptyOrder));
Assert.That(ex.Message, Is.EqualTo("Order must contain at least one item"));

TUnit:

csharp
await Assert.That(() => processor.ProcessOrder(emptyOrder))
    .Throws<InvalidOperationException>()
    .WithMessage("Order must contain at least one item");

// Or, for exact-type matching (no derived types):
await Assert.That(() => processor.ProcessOrder(emptyOrder))
    .ThrowsExactly<InvalidOperationException>();

Mystery Guest — Common .NET Patterns

Smell indicator What to look for
File system File.ReadAllText, File.Exists, File.WriteAllBytes, Directory.GetFiles, Path.Combine with hard-coded paths
Database SqlConnection, DbContext (without in-memory provider), SqlCommand
Network HttpClient without HttpMessageHandler override, WebRequest, TcpClient
Environment Environment.GetEnvironmentVariable, Environment.CurrentDirectory
Acceptable MemoryStream, StringReader, InMemory database providers, custom DelegatingHandler

Integration Test Markers

Recognize these as integration tests (adjust smell severity accordingly):

  • Class name contains Integration, E2E, EndToEnd, or Acceptance
  • [TestCategory("Integration")] (MSTest)
  • [Trait("Category", "Integration")] (xUnit)
  • [Category("Integration")] (NUnit, TUnit)
  • Project name ending in .IntegrationTests or .E2ETests

Setup/Teardown Methods

Framework Setup Teardown
MSTest [TestInitialize] or constructor [TestCleanup] or IDisposable.Dispose / IAsyncDisposable.DisposeAsync
xUnit constructor IDisposable.Dispose / IAsyncDisposable.DisposeAsync
NUnit [SetUp] [TearDown]
TUnit [Before(Test)] or constructor [After(Test)] or IDisposable.Dispose / IAsyncDisposable.DisposeAsync
MSTest (class) [ClassInitialize] [ClassCleanup]
NUnit (class) [OneTimeSetUp] [OneTimeTearDown]
xUnit (class) IClassFixture<T> fixture's Dispose
TUnit (class) [Before(Class)] [After(Class)]
TUnit (assembly) [Before(Assembly)] [After(Assembly)]
TUnit (session) [Before(TestSession)] [After(TestSession)]

TUnit-specific: [BeforeEvery(Test)] / [AfterEvery(Test)] (and the Class / Assembly variants) run for every test/class/assembly across the whole test run — useful for global cross-cutting hooks. Hooks may optionally accept a context object (TestContext, ClassHookContext, etc.) and/or a CancellationToken.

Explore more skills

Browse all
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

More from .NET

View source →
analyzing-dotnet-performanceScans .NET code for ~50 performance anti-patterns across async, memory, strings, collections, LINQ, regex, serialization, and I/O with tiered severity classification. Use when analyzing .NET code for optimization opportunities, reviewing…16 installscreate-skillScaffolds new agent skills for the dotnet/skills repository. Use when creating a new skill, generating SKILL.md files, writing a skill description that the runtime will actually route to, or setting up skill directory structures. Handles…10 installscsharp-scriptsRun file-based C# apps with the .NET CLI when the user explicitly wants C#/.NET code without creating a project. Use for C# language/API experiments, one-file C# apps, small multi-file C# apps composed with `#:include`/`#:exclude`, or C#…6 installscode-testing-extensionsProvides file paths to language-specific extension files for the code-testing pipeline. Read this reference-only catalog for extension guidance files (e.g., dotnet.md for .NET, cpp.md for C++). Agents and skills read its bundled files…4 installsmigrate-nullable-referencesEnable nullable reference types in a C# project and systematically resolve all warnings. USE FOR: adopting NRTs in existing codebases, file-by-file or project-wide migration, fixing CS8602/CS8618/CS86xx warnings, annotating APIs for…3 installscreate-blazor-projectCreate a new ASP.NET Core web application or web site using Blazor. USE FOR: creating a new Blazor web app, scaffolding a new web project, starting a new web site, choosing render modes (Static SSR, Interactive Server, Interactive…3 installs

Frequently asked questions about dotnet-test-frameworks

What does the dotnet-test-frameworks skill do?

Reference data for .NET test framework detection patterns, assertion APIs, skip annotations, setup/teardown methods, and common test smell indicators across MSTest, xUnit, NUnit, and TUnit. Loaded by test analysis skills (test-anti-patterns) as framework-specific lookup tables. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the dotnet-test-frameworks skill?

Run `npx @skills-hub-ai/cli install dotnet-test-frameworks` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/dotnet-test-frameworks/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does dotnet-test-frameworks work with?

dotnet-test-frameworks runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the dotnet-test-frameworks skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use dotnet-test-frameworks after installing it?

In Claude Code, type `/dotnet-test-frameworks` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the dotnet-test-frameworks skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.

Badge for your README

Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.

Install on Skills Hub badge preview
Markdown
[![Install on Skills Hub](https://skills-hub.ai/api/badges/skill/dotnet-test-frameworks)](https://skills-hub.ai/skills/dotnet-test-frameworks)
HTML
<a href="https://skills-hub.ai/skills/dotnet-test-frameworks"><img src="https://skills-hub.ai/api/badges/skill/dotnet-test-frameworks" alt="Install on Skills Hub"></a>

More options in the badge docs.