Agent Skills: Test Generator Skill

Generates unit tests for code. Analyzes functions/classes and creates comprehensive test cases. Use when users want tests, mention "write tests", "add unit tests", "test coverage", or TDD workflows.

qualityID: IHKREDDY/agent-skills-ts/test-generator

Install this agent skill to your local

pnpm dlx add-skill https://github.com/IHKREDDY/agent-skills-ts/tree/HEAD/skills/test-generator

Skill Files

Browse the full folder contents for test-generator.

Download Skill

Loading file tree…

skills/test-generator/SKILL.md

Skill Metadata

Name
test-generator
Description
Generates unit tests for code. Analyzes functions/classes and creates comprehensive test cases. Use when users want tests, mention "write tests", "add unit tests", "test coverage", or TDD workflows.

Test Generator Skill

🎯 Use Case Demo

Scenario

Developer Mike just wrote a new BookingService with 5 methods. He needs unit tests but testing takes forever to write.

Before (Manual):

// Spend 30 minutes writing one test...
[Fact]
public void CreateBooking_ValidData_ReturnsBooking()
{
    // Arrange... Act... Assert... 😴
}

After (With Skill):

"Generate tests for BookingService.cs"

public class BookingServiceTests
{
    private readonly Mock<IFlightRepository> _flightRepo;
    private readonly Mock<IBookingRepository> _bookingRepo;
    private readonly BookingService _sut;

    public BookingServiceTests()
    {
        _flightRepo = new Mock<IFlightRepository>();
        _bookingRepo = new Mock<IBookingRepository>();
        _sut = new BookingService(_flightRepo.Object, _bookingRepo.Object);
    }

    [Fact]
    public void CreateBooking_WithValidFlight_ReturnsNewBooking()
    {
        // Arrange
        var flight = new Flight { Id = 1, AvailableSeats = 10 };
        _flightRepo.Setup(r => r.GetById(1)).Returns(flight);
        
        // Act
        var result = _sut.CreateBooking(1, "John Doe", "john@example.com");
        
        // Assert
        Assert.NotNull(result);
        Assert.Equal("John Doe", result.PassengerName);
    }

    [Fact]
    public void CreateBooking_FlightNotFound_ThrowsException()
    {
        // Arrange
        _flightRepo.Setup(r => r.GetById(99)).Returns((Flight)null);
        
        // Act & Assert
        Assert.Throws<FlightNotFoundException>(() => 
            _sut.CreateBooking(99, "John", "john@example.com"));
    }

    [Theory]
    [InlineData("")]
    [InlineData(null)]
    [InlineData("   ")]
    public void CreateBooking_InvalidPassengerName_ThrowsValidationException(string name)
    {
        // Arrange & Act & Assert
        Assert.Throws<ValidationException>(() => 
            _sut.CreateBooking(1, name, "john@example.com"));
    }

    // ... 10 more comprehensive tests generated
}

Time Saved: 2-3 hours per service class


When to Use This Skill

  • After writing new code
  • When improving test coverage
  • Before submitting PRs
  • For TDD (write tests first)

Test Types Generated

| Type | Purpose | Example | |------|---------|---------| | Happy Path | Normal operation | Valid input β†’ expected output | | Edge Cases | Boundary conditions | Empty, null, max values | | Error Cases | Exception handling | Invalid input β†’ proper exception | | Integration | Component interaction | Service β†’ Repository β†’ DB |

Agent Instructions

When user asks for tests:

  1. Read the source file to understand:

    • Class structure and dependencies
    • Public methods to test
    • Input/output types
    • Possible exceptions
  2. Identify test scenarios:

    • Happy path for each method
    • Null/empty inputs
    • Boundary values
    • Exception conditions
  3. Generate test class:

    • Setup with mocks
    • Arrange-Act-Assert pattern
    • Descriptive test names
    • Theory/InlineData for parameterized tests
  4. Match project framework:

    • .NET β†’ xUnit + Moq
    • Node.js β†’ Jest
    • Python β†’ pytest

Example Prompts

User: "Write tests for BookingService" β†’ Generate comprehensive test file

User: "Add edge case tests for CreateBooking method" β†’ Focus on specific method edge cases

User: "What scenarios should I test?" β†’ List test cases without code

Demo Script

# 1. Show existing service
cat Services/BookingService.cs

# 2. Ask agent: "Generate unit tests for BookingService"

# 3. Agent creates BookingServiceTests.cs with:
#    - 15+ test methods
#    - Mocked dependencies
#    - Edge cases covered

# 4. Run tests
dotnet test

Benefits

| Metric | Before | After | Improvement | |--------|--------|-------|-------------| | Test writing time | 2-3 hours | 5 minutes | ⬇️ 95% | | Test coverage | 30-50% | 80-90% | ⬆️ 2x | | Edge cases found | Often missed | Comprehensive | βœ… Complete | | TDD adoption | Difficult | Easy | βœ… Enabled |