testing

Testing strategy for .NET 10 applications. Covers xUnit v3, WebApplicationFactory for integration tests, Testcontainers for real database testing, Verify for snapshot testing, and the AAA pattern. Load this skill when writing tests, setting up test infrastructure, reviewing test coverage, or when th

By codewithmukesh · 1,200 installs

npx skills add codewithmukesh/dotnet-claude-kit --skill testing

Source repository · Upstream listing

Testing (.NET 10) Core Principles 1. Integration tests are the highest value tests — A single WebApplicationFactory test covers routing, binding, validation, business logic, and persistence in one shot. Start here before writing unit tests. 2. Real databases in tests — Use Testcontainers to spin up real PostgreSQL/SQL Server instances. In memory providers hide real bugs (transactions, constraints, SQL generation). 3. AAA pattern is mandatory — Every test has three clearly separated sections: Arrange, Act, Assert. No mixing. 4. Test behavior, not implementation — Tests should survive refactoring. Test what the system does, not how it does it. Patterns xUnit v3 Basics Integration Tests with WebApplicationFactory The highest value test pattern. Tests the full HTTP pipeline. Testcontainers for Real Database Testing Verify Snapshot Testing Use Verify for complex response objects where manual assertions would be fragile. On first run, Verify creates a .verified.txt file. On subsequent runs, it compares output. If the output changes, the test fails and shows a diff. Test Data Builders Testing Time Dependent Code Use TimeProvider (built into .NET 8+) and FakeTimeProvider from Microsoft.Extensions.TimeProvider.Testing . Test Naming Convention Use the pattern: MethodName StateUnderTest ExpectedBehavior Anti patterns Don't Use In Memory Database for Integration Tests Don't Test Implementation Details Don't Share Mutable State Between Tests Don't Write Assertion Free Tests Decision Guide Scenario Recommendation Testing an API endpoint WebApplicationFactory integration test Testing business logic in isolation Unit test with fakes/stubs Database dependent tests Testcontainers (real DB) Complex response validation Verify snapshot testing Time dependent logic FakeTimeProvider External API dependency WireMock.Net or HttpMessageHandler stub Parameterized test cases [Theory] with [InlineData] or [MemberData] Test data setup Builder pattern Shared expensive fixture IClassFixture<T with IAsyncLifetime