What problem does it solve?
XUnit testing can be inconsistent and hard to maintain without a clear set of best practices. This Skill provides structured guidance to write clean, reliable unit tests in .NET using XUnit, including standard and data-driven approaches, naming conventions, and test organization.
Core Features & Use Cases
- Project Setup: Create a dedicated test project named [ProjectName].Tests and reference Microsoft.NET.Test.Sdk, xunit, and xunit.runner.visualstudio.
- Test Structure: Use the Arrange-Act-Assert pattern; use [Fact] for simple tests; follow naming conventions such as MethodName_Scenario_ExpectedBehavior.
- Data-Driven Testing: Use [Theory], [InlineData], [MemberData], or [ClassData] to cover multiple scenarios.
- Assertions & Mocking: Apply a mix of Assert methods and mocking frameworks (e.g., Moq) to isolate units.
Quick Start
Create a test project named MyApp.Tests, reference the required NuGet packages, and implement a sample CalculatorTests class using the AAA pattern.