← ClaudeAtlas

testing-dotnetlisted

.NET testing patterns — xUnit conventions, integration tests with WebApplicationFactory, mocking strategies, and test organization.
zdanovichnick/dotnet-pilot · ★ 3 · Testing & QA · score 76
Install: claude install-skill zdanovichnick/dotnet-pilot
# .NET Testing Patterns Reference for test generation. Used by `dnp-test-writer`, `dnp-tdd-developer-easy`, `dnp-tdd-developer-hard`, and `dnp-planner`. ## Test Organization ``` tests/ ├── MyApp.UnitTests/ # Fast, isolated, mock dependencies │ ├── Services/ │ │ └── UserServiceTests.cs │ └── Domain/ │ └── UserTests.cs ├── MyApp.IntegrationTests/ # Slower, real dependencies │ ├── Api/ │ │ └── UserEndpointTests.cs │ └── Infrastructure/ │ └── UserRepositoryTests.cs └── MyApp.ArchitectureTests/ # Optional: enforce architecture rules └── LayerDependencyTests.cs ``` ## xUnit Patterns ### Test Class Setup ```csharp public class UserServiceTests { private readonly Mock<IUserRepository> _repo; private readonly UserService _sut; // system under test public UserServiceTests() { _repo = new Mock<IUserRepository>(); _sut = new UserService(_repo.Object); } } ``` ### Naming Convention `MethodName_StateUnderTest_ExpectedBehavior` ```csharp [Fact] public async Task GetByIdAsync_WhenUserExists_ReturnsUser() { } [Fact] public async Task GetByIdAsync_WhenUserNotFound_ReturnsNull() { } [Theory] [InlineData("")] [InlineData(null)] public async Task CreateAsync_WithInvalidEmail_ThrowsValidationException(string? email) { } ``` ### IClassFixture for Shared Setup ```csharp public class DatabaseTests : IClassFixture<DatabaseFixture> { private readonly DatabaseFixture _fixture; public DatabaseTests(Databa