.claude/skills/dotnet-test/SKILL.md
Manages unit tests using xUnit in .NET projects. Creates the test project if it doesn't exist, organizes tests by layer (Domain, Application, Infra, API), mirrors the source folder structure, and generates test files. Use when creating, updating, or organizing unit tests.
npx skillsauth add emaginebr/Peleja dotnet-testInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are an expert assistant that helps developers create and manage unit tests using xUnit in .NET projects. You follow a strict convention for project structure, naming, and organization.
The user will describe what to test: $ARGUMENTS
Before generating tests:
.sln file.Tests (e.g., MyApp.Tests)Create only one test project for the entire solution, named {SolutionName}.Tests.
MySolution/
├── MySolution.sln
├── MySolution.API/
├── MySolution.Application/
├── MySolution.Domain/
├── MySolution.Infra/
├── MySolution.Infra.Interfaces/
├── MySolution.DTO/
└── MySolution.Tests/ ← Single test project
├── MySolution.Tests.csproj
├── Domain/
│ ├── Services/
│ │ ├── ProductServiceTest.cs
│ │ └── OrderServiceTest.cs
│ └── Mappers/
│ └── ProductMapperTest.cs
├── Application/
│ └── StartupTest.cs
├── Infra/
│ ├── Repository/
│ │ └── ProductRepositoryTest.cs
│ └── Mappers/
│ └── ProductDbMapperTest.cs
└── API/
└── Controllers/
└── ProductControllerTest.cs
Domain/, Application/, Infra/, API/, etc.Services/, Repository/, Mappers/, Controllers/){ClassName}Test.cs (e.g., ProductService → ProductServiceTest.cs)If the test project does not exist, create it:
# 1. Create the xUnit project
dotnet new xunit -n {SolutionName}.Tests -o {SolutionName}.Tests
# 2. Add it to the solution
dotnet sln {SolutionName}.sln add {SolutionName}.Tests/{SolutionName}.Tests.csproj
# 3. Add references to all projects that need testing
dotnet add {SolutionName}.Tests/{SolutionName}.Tests.csproj reference {SolutionName}.Domain/{SolutionName}.Domain.csproj
dotnet add {SolutionName}.Tests/{SolutionName}.Tests.csproj reference {SolutionName}.Infra/{SolutionName}.Infra.csproj
dotnet add {SolutionName}.Tests/{SolutionName}.Tests.csproj reference {SolutionName}.Application/{SolutionName}.Application.csproj
dotnet add {SolutionName}.Tests/{SolutionName}.Tests.csproj reference {SolutionName}.API/{SolutionName}.API.csproj
# ... add all projects that contain classes to test
# 4. Add Moq for mocking
dotnet add {SolutionName}.Tests/{SolutionName}.Tests.csproj package Moq
# 5. Delete the default UnitTest1.cs
rm {SolutionName}.Tests/UnitTest1.cs
The test project must have:
xunit (included by template)xunit.runner.visualstudio (included by template)Microsoft.NET.Test.Sdk (included by template)Moq (add manually){ClassName}Test (e.g., ProductServiceTest){SolutionName}.Tests.{Layer}.{SubFolder} (e.g., MyApp.Tests.Domain.Services){MethodName}_Should{ExpectedBehavior}_When{Condition} (e.g., InsertAsync_ShouldThrowException_WhenNameIsEmpty)using Xunit;
using Moq;
// ... other usings
namespace {SolutionName}.Tests.{Layer}.{SubFolder}
{
public class {ClassName}Test
{
private readonly Mock<IDependency1> _dependency1Mock;
private readonly Mock<IDependency2> _dependency2Mock;
private readonly {ClassName} _sut; // System Under Test
public {ClassName}Test()
{
_dependency1Mock = new Mock<IDependency1>();
_dependency2Mock = new Mock<IDependency2>();
_sut = new {ClassName}(
_dependency1Mock.Object,
_dependency2Mock.Object
);
}
[Fact]
public async Task {MethodName}_Should{Expected}_When{Condition}()
{
// Arrange
// ...
// Act
// ...
// Assert
// ...
}
[Theory]
[InlineData("", false)]
[InlineData("valid", true)]
public async Task {MethodName}_ShouldValidate_When{Condition}(string input, bool expected)
{
// Arrange, Act, Assert
}
}
}
UseInMemoryDatabase) for EF Core repository testsUnauthorized() when no sessionNotFound() for missing resourcesForbid() for access deniedOk() with correct data# Run all tests
dotnet test {SolutionName}.Tests
# Run with verbose output
dotnet test {SolutionName}.Tests --verbosity normal
# Run specific test class
dotnet test {SolutionName}.Tests --filter "FullyQualifiedName~ProductServiceTest"
# Run specific test method
dotnet test {SolutionName}.Tests --filter "FullyQualifiedName~InsertAsync_ShouldThrowException_WhenNameIsEmpty"
Before finishing, verify:
Test.cs{Method}_Should{What}_When{Condition}dotnet build {SolutionName}.Testsdotnet test {SolutionName}.Teststools
Guides how to integrate the zTools package for ChatGPT, DALL-E image generation, file upload (S3), slug generation, email sending, and document validation in a .NET 8 project. Use when the user wants to use AI features, upload files, generate slugs, send emails, or understand zTools integration.
documentation
Generates a comprehensive, standardized README.md for any project. Use when the user wants to create or regenerate a README file following the project's documentation standard.
development
Guides how to integrate the NNews NuGet package for consuming the NNews CMS API in a .NET 8 project. Use when the user wants to consume articles, categories, tags, images, or AI-powered content generation from the NNews API.
tools
Guides how to integrate the NAuth package for user authentication in a .NET 8 project. Use when the user wants to add authentication, configure NAuth, use IUserClient, or understand the NAuth authentication flow.