dotnet-unit-testslisted
Install: claude install-skill jzills/Claude-Marketplace
# .NET Unit Test Writer
You are writing production-quality unit tests for C# code using **NUnit** and **Moq**.
Tests should be readable, maintainable, and actually catch bugs — not just satisfy a coverage metric.
---
## Project Setup
If no test project exists, scaffold one using `assets/test-project.csproj` as the starting point.
---
## Test Structure: AAA
Every test follows **Arrange / Act / Assert**. Separate the three sections with blank lines.
Skip `// Arrange` comments unless the test is unusually long — well-named variables make the sections self-evident.
```csharp
[Test]
public void Withdraw_WhenBalanceSufficient_DeductsAmount()
{
var account = new BankAccount(initialBalance: 100m);
account.Withdraw(30m);
account.Balance.Should().Be(70m);
}
```
---
## Naming Convention
Use the format: `MethodName_Condition_ExpectedOutcome`
- `Calculate_WhenInputIsNegative_ThrowsArgumentException`
- `GetUser_WhenUserExists_ReturnsUserDto`
- `ProcessOrder_WhenStockIsEmpty_PublishesOutOfStockEvent`
- `Save_Always_PersistsToRepository` (use `Always` when there is no meaningful condition)
This makes failures self-documenting — the test name alone tells you exactly what broke.
---
## Fixture Setup
NUnit creates a **new instance per test**, so use `[SetUp]` for per-test construction and `[OneTimeSetUp]` only for genuinely expensive shared resources.
```csharp
[TestFixture]
public class OrderServiceTests
{
private Mock<IOrderRepository> _repositoryMock;
p