Xunit
xUnit .NET testing framework. Use for .NET testing.From its SKILL.md
npx -y skills add G1Joshi/Agent-Skills --skill xunitAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 12 stars12 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
1.7 KB, 425 tokens by cl100k_base, as published. Nobody here has run it
xUnit.net
xUnit.net is the modern, open-source unit testing tool for .NET (C#, F#, VB). It is chosen by Microsoft/dotnet for their own repositories.
When to Use
- .NET Core / .NET 5+: The default template choice.
- Modern Practices: Enforces good habits (Isolation, Constructor Injection for fixtures).
Quick Start
using Xunit;
public class CalculatorTests
{
[Fact]
public void PassingTest()
{
Assert.Equal(4, Add(2, 2));
}
[Theory]
[InlineData(3)]
[InlineData(5)]
[InlineData(6)]
public void MyTheory(int value)
{
Assert.True(IsOdd(value));
}
}
Core Concepts
Facts vs Theories
[Fact]: A test that is always true. Invariant.[Theory]: A test that is true for a particular set of data (Parameterized).
Fixtures (IClassFixture)
xUnit creates a new instance of the Test Class for every test method (High isolation). To share context (like a DB connection), implement IClassFixture<T>.
Assert
Assert.Equal, Assert.Throws, Assert.Collection.
Best Practices (2025)
Do:
- Use
xunit.runner.visualstudio: To run tests in VS/VS Code. - Use FluentAssertions: xUnit's asserts are okay, but
value.Should().Be(4)(FluentAssertions) is much more readable. - Constructor Injection: Use the constructor for Setup, and
Dispose()(IDisposable) for Teardown. xUnit abolished[SetUp]and[TearDown]attributes to force cleaner design.
Don't:
- Don't use
Console.WriteLine: UseITestOutputHelperinjected in the constructor to log outputs.
References
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.