dotnet-testing

Guide .NET testing with xUnit, NSubstitute, and FluentAssertions.

Updated Feb 5, 2026
One-click install
npx skills add https://github.com/Objective-Arts/lens --skill dotnet-testing-objective-arts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-testing
Source: https://github.com/Objective-Arts/lens/tree/main/canon/csharp/dotnet-testing
Command: npx skills add https://github.com/Objective-Arts/lens --skill dotnet-testing-objective-arts

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps .NET developers write more effective, maintainable, and robust unit and integration tests, reducing bugs and improving code quality.

Core Features & Use Cases

  • Test Structure & Naming: Enforces clear Arrange-Act-Assert patterns and descriptive test names.
  • xUnit Best Practices: Guides on using [Fact] vs [Theory] and appropriate data attributes.
  • Mocking Strategies: Recommends using NSubstitute for mocking external dependencies effectively.
  • Assertion Libraries: Promotes FluentAssertions for readable and expressive assertions.
  • Integration Testing: Demonstrates using WebApplicationFactory for testing ASP.NET Core applications.
  • Database Testing: Provides strategies for testing with SQLite in-memory or Testcontainers.
  • Async Testing: Covers best practices for testing asynchronous code, including cancellation and timeouts.
  • Test Organization: Advises on structuring test classes and using fixtures (IClassFixture, ICollectionFixture).
  • Anti-Pattern Avoidance: Highlights common pitfalls in testing and how to fix them.

Quick Start

Use the dotnet-testing skill to refactor a test method to follow the Arrange-Act-Assert pattern.

Frequently Asked Questions about dotnet-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure xUnit tests in .NET to follow best practices?

xUnit best practices involve using the Arrange-Act-Assert pattern, selecting [Fact] vs [Theory] with appropriate data attributes, and organizing tests with IClassFixture or ICollectionFixture to ensure maintainability and clear descriptive naming.

What's the best way to mock external dependencies in .NET integration tests?

The best way to mock external dependencies in .NET testing is using NSubstitute, which allows you to effectively substitute external components while maintaining readable and expressive test suites.

How do I test ASP.NET Core applications using WebApplicationFactory?

You test ASP.NET Core applications using WebApplicationFactory for integration testing, which allows you to boot up your application in memory and test the full request pipeline end-to-end.

Should I use SQLite in-memory or Testcontainers for .NET database testing?

SQLite in-memory provides fast, lightweight database testing for .NET, while Testcontainers offers realistic integration testing using actual database engines in Docker containers for higher fidelity.

How do I handle async test patterns and avoid common anti-patterns in .NET testing?

Handle async test patterns in .NET by properly awaiting asynchronous operations, testing cancellation and timeouts, and avoiding common anti-patterns highlighted by best practices to ensure robust and maintainable test suites.

Can I use FluentAssertions to make my .NET test assertions more readable?

Yes, FluentAssertions promotes readable and expressive assertions in .NET testing, allowing you to write clear test verification statements that integrate smoothly with xUnit and NSubstitute.