csharp-testing

Write C# and .NET tests using xUnit, FluentAssertions, and Testcontainers.

Updated Sep 13, 2025
One-click install
npx skills add https://github.com/llmh333/employee_management_spring --skill csharp-testing-llmh333
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-testing
Source: https://github.com/llmh333/employee_management_spring/tree/main/.gemini/skills/csharp-testing
Command: npx skills add https://github.com/llmh333/employee_management_spring --skill csharp-testing-llmh333

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you write trustworthy C# test suites that are readable, maintainable, and less prone to flakiness, so you can validate behavior confidently as your .NET codebase grows.

Core Features & Use Cases

  • Behavior-focused unit testing: Structure tests with Arrange-Act-Assert, verify outcomes, and avoid implementation-detail assertions.
  • Strong mocking for dependencies: Use NSubstitute or Moq to isolate the system under test and precisely verify interactions.
  • Realistic integration testing: Run ASP.NET Core integration tests with WebApplicationFactory and use Testcontainers for Postgres-backed scenarios.
  • Better test data and organization: Use builders (e.g., OrderBuilder) and consistent folder conventions to scale test code cleanly.

Quick Start

Ask the AI to generate a complete xUnit test suite for an ASP.NET Core endpoint, including at least one unit test, one integration test with WebApplicationFactory, and one Testcontainers-backed repository test.

Frequently Asked Questions about csharp-testing

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

FAQPage Schema
How do I write reliable C# integration tests for ASP.NET Core endpoints?

To write reliable C# integration tests, use xUnit with WebApplicationFactory to run ASP.NET Core endpoints in-memory and FluentAssertions to verify outcomes. This combination isolates behavior and avoids implementation-detail assertions to reduce flakiness as your codebase grows.

What is the best way to isolate dependencies when unit testing .NET services?

The best way to isolate dependencies during .NET unit testing is using mocking libraries like NSubstitute or Moq. These tools isolate the system under test, allowing you to structure tests with Arrange-Act-Assert and precisely verify interactions without hitting real infrastructure.

How does Testcontainers work for Postgres-backed repository tests in .NET?

Testcontainers works for .NET repository tests by spinning up real Postgres Docker containers during the test run. This infrastructure-aware approach validates actual database interactions, replacing flaky mocks with reliable, ephemeral Postgres instances managed within xUnit test suites.

Can I use FluentAssertions with xUnit to organize large .NET test suites?

Yes, you can use FluentAssertions with xUnit to build readable .NET test suites. Combined with builder patterns like OrderBuilder and consistent folder conventions, this approach keeps test data structured and scales test code cleanly across large services and repositories.

Why does my C# test suite keep failing intermittently?

Your C# test suite likely fails intermittently due to implementation-detail assertions or reliance on shared state instead of behavior-focused verification. Diagnose flaky behavior by restructuring tests with Arrange-Act-Assert, isolating dependencies via NSubstitute, and using WebApplicationFactory for realistic environments.

Does the csharp-testing approach support both unit and infrastructure-aware integration tests?

Yes, csharp-testing supports both unit and infrastructure-aware integration tests. It provides patterns for behavior-focused unit testing with NSubstitute and realistic integration testing using WebApplicationFactory and Testcontainers, ensuring consistent test naming and clean validation across .NET projects.