csharp-xunit

Guides writing, reviewing, and refactoring xUnit unit tests in C# projects.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, maintainable unit tests in C# requires knowing xUnit conventions, data-driven testing patterns, and proper assertion usage, which developers often get wrong or apply inconsistently. ## Core Features & Use Cases - Test Structure Guidance: Enforces AAA pattern, naming conventions like MethodName_Scenario_ExpectedBehavior, and proper setup/teardown with constructors, IDisposable, and fixtures. - Data-Driven Testing: Covers [Theory] with [InlineData], [MemberData], [ClassData], and custom DataAttribute implementations for parameterized tests. - Assertions and Mocking: Recommends correct Assert methods, exception testing with Assert.ThrowsAsync, and isolation using Moq or NSubstitute. - Use Case: When refactoring a legacy Calculator class, use this Skill to generate a CalculatorTests project with [Fact] tests for simple cases and [Theory] tests covering edge-case inputs. ## Quick Start Write xUnit tests for my C# class using [Fact] and [Theory] with proper AAA structure and naming conventions.

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-based data, or [ClassData] for class-based data. You can also create custom data attributes by implementing DataAttribute.

What is the difference between [Fact] and [Theory] in xUnit?▼

[Fact] marks a simple test that runs once with no parameters, while [Theory] marks a parameterized test that runs once per data row supplied by attributes like [InlineData] or [MemberData].

How do I test exceptions in xUnit?▼

Use Assert.Throws<T> for synchronous code or await Assert.ThrowsAsync<T> for asynchronous methods. These verify that the expected exception type is thrown during the Act phase of the test.

Does xUnit support shared setup between tests?▼

Yes. Use the test class constructor for per-test setup and IDisposable.Dispose for teardown. For shared context across tests in a class use IClassFixture<T>, and across multiple classes use ICollectionFixture<T>.

Which mocking frameworks work with xUnit?▼

Moq and NSubstitute both work alongside xUnit to mock dependencies and isolate the unit under test. Designing code around interfaces and using a DI container for complex setups facilitates mocking.