xunit
Skill15 starsChanged 2 months agoMITView on GitHub
Expert xUnit.net testing assistance covering .NET Fact/Theory tests, constructor fixtures, and output capture. Use when writing C# unit tests, testing ASP.NET Core applications, or running `dotnet test`.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- yellow-hammer/skills-xunittheir own version, first seen Oct 25, 2026
- Sorcha-Platform/Sorchatheir own version, first seen Jan 24, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- yellow-hammer/skills-xunit★ 4same name
- Sorcha-Platform/Sorcha★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 110
Use [Theory] with [InlineData]:
- Very specific: line 134
Use Constructors for Setup and Dispose() for Teardown: Implement IDisposable or IAsyncLifetime rather than looking for [SetUp].
- Very specific: line 135
Use IClassFixture<T> for Shared State: Share heavy dependencies (like Testcontainers or WebApplicationFactory) cleanly.
- Distinctive: line 137
Run Tests in Parallel: Leverage xUnit's default parallelization across test collections.
- Distinctive: line 141
Use static variables in test classes: xUnit runs test classes in parallel.
- Very specific: line 142
Write Assert.True(x == y): Use Assert.Equal(expected, actual) for informative failure diff messages.
- Very specific: line 143
Create asynchronous void tests: Always return async Task from test methods.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
- Modern .NET Core Unit Testing: The modern, opinionated, community-preferred testing framework for C# and ASP.NET Core applications.
- Isolated Clean Test Execution: Enforcing a new class instance for every single test method to guarantee zero state contamination.
- Theory-Driven Parameterized Tests: Running tests across inline data (
[InlineData]), member data, and class data sources. - Constructor-Based Test Setup: Replacing
[SetUp]attributes with standard C# object-oriented constructors andIDisposable.
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
Instance-Per-Test Lifecycle Architecture
Unlike NUnit and MSTest, xUnit instantiates a completely new instance of the test class for every [Fact], preventing shared instance field state:
[ Test Class ] ──new()──→ Runs Fact 1 ──Dispose()
[ Test Class ] ──new()──→ Runs Fact 2 ──Dispose()Facts vs Theories ([Fact] vs [Theory])
[Fact]: Test that is always true and tests invariant conditions.[Theory]: Parameterized test that executes across datasets:
using Xunit;
public class OrderValidatorTests
{
[Fact]
public void EmptyOrder_IsInvalid()
{
var order = new Order();
Assert.False(order.IsValid());
}
[Theory]
[InlineData(100, "DISCOUNT10", 90)]
[InlineData(50, "SAVE5", 45)]
[InlineData(20, "", 20)]
public void ApplyDiscount_CalculatesCorrectTotal(decimal price, string code, decimal expected)
{
var total = OrderService.CalculateTotal(price, code);
Assert.Equal(expected, total);
}
}Shared Context via Class Fixtures (IClassFixture<T>)
Shares expensive setup (database, web test servers) across tests without static state:
public class DatabaseFixture : IDisposable
{
public SqlConnection Connection { get; }
public DatabaseFixture() { Connection = new SqlConnection("Server=localhost;..."); Connection.Open(); }
public void Dispose() { Connection.Dispose(); }
}
public class CustomerRepositoryTests : IClassFixture<DatabaseFixture>
{
private readonly DatabaseFixture _fixture;
public CustomerRepositoryTests(DatabaseFixture fixture) => _fixture = fixture;
[Fact]
public void QueriesCustomerRecord() { /* Uses _fixture.Connection */ }
}Common Patterns
Theory with InlineData and ClassData
Problem: Writing duplicate test methods for multiple inputs in C# applications.
Solution:
Use [Theory] with [InlineData]:
using Xunit;
public class MathTests
{
[Theory]
[InlineData(2, 3, 5)]
[InlineData(-1, 1, 0)]
[InlineData(0, 0, 0)]
public void Add_ValidInputs_ReturnsExpectedSum(int a, int b, int expected)
{
var calculator = new Calculator();
var result = calculator.Add(a, b);
Assert.Equal(expected, result);
}
}Best Practices
Do:
- Use Constructors for Setup and
Dispose()for Teardown: ImplementIDisposableorIAsyncLifetimerather than looking for[SetUp]. - Use
IClassFixture<T>for Shared State: Share heavy dependencies (like Testcontainers or WebApplicationFactory) cleanly. - Inject
ITestOutputHelperfor Logging: Write test logs viaITestOutputHelperrather thanConsole.WriteLine(). - Run Tests in Parallel: Leverage xUnit's default parallelization across test collections.
Don't:
- Use static variables in test classes: xUnit runs test classes in parallel; static state introduces race conditions.
- Write
Assert.True(x == y): UseAssert.Equal(expected, actual)for informative failure diff messages. - Create asynchronous void tests: Always return
async Taskfrom test methods;async voidexceptions crash the test runner.
Troubleshooting
| Error | Cause | Solution |
No test matches the given testcase filter | Filter string doesn't match namespace or class name. | Run dotnet test --filter FullyQualifiedName~MathTests. |
Console.WriteLine produces no output | xUnit isolates console output to prevent race conditions. | Inject ITestOutputHelper in constructor and call _output.WriteLine(). |
Assert.Equal() Failure: Expected ... Actual ... | Output mismatch in assertion. | Review diff and check floating-point precision with tolerance arguments. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

