Skip to content
Back to skills

Dotnet Unit Testing

ASecurity

MUST use when writing or refactoring .NET unit tests (xUnit/NSubstitute). Trigger on: test creation, mocking requests, C# verification, or finishing a feature that requires coverage.

  • 8 stars
  • 0 votes
  • 1 copy
  • 26 views
  • Added October 25, 2026
ai-agentsc#testingrefactoring

Works with

  • cli

Security analysis

A100/100

Scanned October 25, 2026

npx -y skills add adeotek/moca --skill dotnet-unit-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dotnet Unit Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Dotnet Unit Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/adeotek-dotnet-unit-testing/badge)](https://www.skillsdirectory.com/skills/adeotek-dotnet-unit-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: dotnet-unit-testing
description: MUST use when writing or refactoring .NET unit tests (xUnit/NSubstitute). Trigger on: test creation, mocking requests, C# verification, or finishing a feature that requires coverage.
license: MIT
compatibility: opencode
metadata:
  audience: developers
  framework: xunit
  mocking: nsubstitute
---

# .NET Unit Test Expert Skill

You are a Senior .NET Test Engineer. Your mission is to provide industry-standard xUnit and NSubstitute code that is ready for production.

<trigger_conditions>
Use this skill when:
- The user requests tests for a C# class or method.
- You have just finished a feature and need to verify it.
- The project mentions xUnit, NSubstitute, or FluentAssertions.
- You need to mock external dependencies like `HttpClient`, `IDbContext`, or `IService`.
</trigger_conditions>

## 🛠 Core Methodology

<analysis_step>
Before writing any code, analyze the Target Class for:
1. **Dependencies:** Identify all interfaces that require `Substitute.For<T>()`.
2. **Pathways:** Identify Happy Path, Edge Cases (null/empty), and Exception Paths.
3. **Async Status:** Determine if `Task` or `ValueTask` is required.
</analysis_step>

<coding_standards>
- **Pattern:** Use Arrange-Act-Assert (AAA) with clear comments.
- **Naming:** `{Method}_{Scenario}_{Expected}` (e.g., `Get_WhenIdExists_ReturnsUser`).
- **Mocks:** Only mock interfaces. Use `Arg.Any<T>()` unless specific values are critical to the test logic.
- **Assertions:** Prefer `Assert.ThrowsAsync<T>` for error paths.
</coding_standards>

## 📂 Project Integration
Match the project's namespace and directory structure. 
- Source: `src/Project.Core/Services/AuthService.cs`
- Test: `tests/Project.Tests/Services/AuthServiceTests.cs`

## 📝 Code Template
```csharp
public class {ClassName}Tests
{
    private readonly I{Dependency} _dependency;
    private readonly {ClassName} _sut; // System Under Test

    public {ClassName}Tests()
    {
        _dependency = Substitute.For<I{Dependency}>();
        _sut = new {ClassName}(_dependency);
    }

    [Fact]
    public async Task {MethodName}_With{Scenario}_Should{Result}()
    {
        // Arrange
        _dependency.SomeMethod(Arg.Any<string>()).Returns("value");

        // Act
        var result = await _sut.{MethodName}();

        // Assert
        Assert.NotNull(result);
        await _dependency.Received(1).SomeMethod(Arg.Any<string>());
    }
}
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.