| name | planforge-new-test |
| description | Scaffold xUnit test classes with Arrange-Act-Assert, mock setup, proper naming conventions, and trait categories. |
| metadata | {"author":"plan-forge","source":".github/prompts/new-test.prompt.md"} |
description: "Scaffold xUnit test classes with Arrange-Act-Assert, mock setup, proper naming conventions, and trait categories."
agent: "agent"
tools: [read, edit, search, execute]
Create New Test
Scaffold test classes following project conventions.
Test Naming Convention
{MethodUnderTest}_When{Condition}_Should{ExpectedBehavior}
Examples:
CreateProduct_WhenNameIsNull_ShouldThrowValidationException
GetById_WhenNotFound_ShouldReturnNull
CalculateTotal_WhenDiscountApplied_ShouldReturnReducedPrice
Unit Test Pattern
public class {ClassName}Tests
{
private readonly Mock<I{Dependency}> _mockDependency;
private readonly {ClassUnderTest} _sut;
public {ClassName}Tests()
{
_mockDependency = new Mock<I{Dependency}>();
_sut = new {ClassUnderTest}(_mockDependency.Object, NullLogger<{ClassUnderTest}>.Instance);
}
[Fact]
[Trait("Category", "Unit")]
public async Task Method_WhenCondition_ShouldExpected()
{
_mockDependency
.Setup(x => x.GetAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new EntityDto { Id = Guid.NewGuid() });
var result = await _sut.MethodAsync(Guid.NewGuid(), CancellationToken.None);
result.Should().NotBeNull();
}
}
Integration Test Pattern (Testcontainers)
public class {ClassName}IntegrationTests : IAsyncLifetime
{
private readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder()
.WithImage("postgres:16-alpine")
.Build();
public async Task InitializeAsync() => await _postgres.StartAsync();
public async Task DisposeAsync() => await _postgres.DisposeAsync();
[Fact]
[Trait("Category", "Integration")]
public async Task Repository_WhenInserted_ShouldBeRetrievable()
{
}
}
Trait Categories
| Trait | When to Use |
|---|
[Trait("Category", "Unit")] | Pure unit tests with mocks |
[Trait("Category", "Integration")] | Tests hitting real DB |
[Trait("Category", "Smoke")] | Fast subset for PR validation |
Reference Files