← ClaudeAtlas

dotnet-testinglisted

.NET testing advisor. Always use this skill when writing tests in C#, working with xUnit, NUnit, MSTest, Moq, NSubstitute, FluentAssertions, or WebApplicationFactory. Use when the user asks "how do I mock an interface in C#", "mock interface vs concrete class", "how do I test an ASP.NET Core controller", "WebApplicationFactory integration test", "how do I write FluentAssertions", "how do I parametrize tests in C#", or "how do I verify a method was called". Read this skill before writing any .NET test.
AllThingsSmitty/agent-skills · ★ 1 · Testing & QA · score 74
Install: claude install-skill AllThingsSmitty/agent-skills
# .NET Testing xUnit is the modern standard for .NET — it's what ASP.NET Core itself uses internally. Its constructor-based setup (no `[SetUp]` attribute) encourages smaller, more focused test classes. Use it for new projects. ## xUnit basics ```csharp public class UserServiceTests { private readonly UserService _sut; private readonly IUserRepository _repository; // Constructor runs before each test — replaces [SetUp] public UserServiceTests() { _repository = Substitute.For<IUserRepository>(); // NSubstitute _sut = new UserService(_repository); } [Fact] public async Task GetUser_WhenUserExists_ReturnsUser() { // Arrange var userId = "user-1"; _repository.FindByIdAsync(userId, Arg.Any<CancellationToken>()) .Returns(new User(userId, "Alice")); // Act var result = await _sut.GetUserAsync(userId); // Assert result.Should().NotBeNull(); result!.Name.Should().Be("Alice"); } } ``` **Test naming**: `MethodName_Scenario_ExpectedResult` is readable and searchable. Keep it consistent across the project. ## Parametrized tests with `[Theory]` Replace repeated `[Fact]` methods with `[Theory]` + `[InlineData]`: ```csharp [Theory] [InlineData("user@example.com", true)] [InlineData("user+tag@example.com", true)] [InlineData("not-an-email", false)] [InlineData("", false)] public void ValidateEmail_ReturnsExpectedResult(string email, bool expected) {