csharp-xunit

Write XUnit unit tests for C# projects using facts, theories, and data-driven patterns.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, maintainable unit tests in C# requires knowing XUnit's conventions for test structure, data-driven testing, assertions, and isolation, which developers often apply inconsistently across a codebase. ## Core Features & Use Cases - Test Structure Guidance: Apply the Arrange-Act-Assert pattern, [Fact] attributes, constructor setup, IDisposable teardown, and IClassFixture<T>/ICollectionFixture<T> shared contexts. - Data-Driven Testing: Build parameterized tests with [Theory] combined with [InlineData], [MemberData], [ClassData], or custom DataAttribute implementations. - Assertions and Mocking: Use the correct Assert methods for equality, collections, regex, and exceptions, and isolate units with Moq or NSubstitute. - Use Case: When adding tests for a new Calculator class, generate a CalculatorTests class in a [ProjectName].Tests project with properly named MethodName_Scenario_ExpectedBehavior tests runnable via dotnet test. ## Quick Start Write XUnit unit tests for my Calculator class using the AAA pattern, including a data-driven theory with InlineData for the Add method.

Frequently Asked Questions about csharp-xunit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write data-driven tests in XUnit?

Use the [Theory] attribute combined with a data source: [InlineData] for inline values, [MemberData] for method-provided data, or [ClassData] for class-based data. You can also create custom data attributes by implementing DataAttribute.

How to structure XUnit test classes in C#?

Create a separate test project named [ProjectName].Tests referencing Microsoft.NET.Test.Sdk, xunit, and xunit.runner.visualstudio. Name test classes after the class under test, follow the Arrange-Act-Assert pattern, and use MethodName_Scenario_ExpectedBehavior naming.

What is the difference between IClassFixture and ICollectionFixture in XUnit?

IClassFixture<T> shares a single context instance across all tests within one test class. ICollectionFixture<T> shares context across multiple test classes grouped into a collection, useful for expensive shared dependencies.

Can I use Moq or NSubstitute with XUnit?

Yes, XUnit works alongside mocking libraries like Moq or NSubstitute to isolate units under test. Mock dependencies through interfaces, and consider a DI container for complex test setups.

How do I test exceptions in XUnit?

Use Assert.Throws<T> for synchronous code or await Assert.ThrowsAsync<T> for asynchronous methods. These assertions verify that the expected exception type is thrown by the code under test.

How do I run XUnit tests from the command line?

Run tests with the .NET SDK command dotnet test from the solution or test project directory. Tests can be categorized with [Trait("Category", "Name")] and conditionally skipped using the Skip property on fact or theory attributes.