Agent skill
test-generator
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.
Install this agent skill to your Project
npx add-skill https://github.com/IHKREDDY/agent-skills-ts/tree/main/skills/test-generator
Metadata
Additional technical details for this skill
- author
- IHKREDDY
- version
- 1.0
- category
- quality
SKILL.md
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:
-
Read the source file to understand:
- Class structure and dependencies
- Public methods to test
- Input/output types
- Possible exceptions
-
Identify test scenarios:
- Happy path for each method
- Null/empty inputs
- Boundary values
- Exception conditions
-
Generate test class:
- Setup with mocks
- Arrange-Act-Assert pattern
- Descriptive test names
- Theory/InlineData for parameterized tests
-
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 |
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
tech-debt-report
Find TODOs, deprecated APIs, and outdated patterns in codebase
sprint-summary
Generate sprint review summary from completed Jira tickets
api-integration
Design and implement REST API integrations with proper error handling, authentication, rate limiting, and testing. Use when building API clients, integrating third-party services, or when users mention API, REST, webhooks, HTTP requests, or service integration.
work-on-ticket
Pulls ticket details from Jira, creates feature branches with proper naming conventions, and handles planning steps. Use when starting work on a Jira ticket, creating branches for tickets, or when users mention "work on ticket", "start ticket", "create branch for", or Jira ticket IDs.
hotfix-workflow
Rapid hotfix branch creation, fix application, and PR to main
create-ticket
Creates Jira tickets with proper formatting, acceptance criteria, and optionally sets up git branches and pull requests. Use when users want to create a new ticket, log a bug, request a feature, or when they mention "create ticket", "new ticket", "log issue", "file bug", or "create Jira".
Didn't find tool you were looking for?