| name | generate-tests | |||
|---|---|---|---|---|
| description | Generate comprehensive unit tests for the selected code following project testing standards | |||
| agent | agent | |||
| tools |
|
Generate comprehensive unit tests for the provided code following the project's testing standards.
Source File: ${file}
Code to Test:
${selection}
Follow the testing standards defined in:
-
Identify the code type:
- Function/method
- Class
- Module/component
- API endpoint
-
Determine what to test:
- All public functions and methods
- Input validation
- Return values and output
- Error handling and edge cases
- Side effects (if any)
-
Identify dependencies to mock:
- External API calls
- Database operations
- File system access
- Third-party libraries
-
File Location:
- Place test file adjacent to source file
- Use naming convention:
{filename}.test.{ext}ortest_{filename}.py
-
Test Structure:
- Use describe/it blocks (JS/TS) or TestClass/test_ methods (Python)
- Follow Arrange-Act-Assert pattern
- Group related tests logically
-
Coverage Goals:
- Happy path scenarios
- Edge cases (null, undefined, empty, boundary values)
- Error conditions and exceptions
- Async behavior (if applicable)
-
Test Cases to Include:
- Input validation tests
- Expected output tests
- Error handling tests
- Boundary condition tests
- Integration point tests (mocked)
Generate a complete test file with:
// File: {test-file-path}
// 1. Imports (testing framework, mocks, source code)
// 2. Mock setup (if needed)
// 3. Test suites organized by function/method
// 4. Individual test cases following naming conventions
- TypeScript/JavaScript: Use Jest or Vitest based on project config
- Python: Use pytest
- React Components: Use React Testing Library
- API Endpoints: Use supertest or httpx
For a TypeScript function:
import { describe, it, expect, beforeEach, jest } from '@jest/globals';
import { functionName } from './source-file';
describe('functionName', () => {
describe('when given valid input', () => {
it('should return expected result', () => {
// Arrange
const input = createValidInput();
// Act
const result = functionName(input);
// Assert
expect(result).toEqual(expectedOutput);
});
});
describe('when given invalid input', () => {
it('should throw ValidationError', () => {
expect(() => functionName(null)).toThrow(ValidationError);
});
});
describe('edge cases', () => {
it('should handle empty array', () => { /* ... */ });
it('should handle maximum values', () => { /* ... */ });
});
});- Analyze the provided code to understand its purpose and behavior
- Identify all testable scenarios (happy paths, edge cases, errors)
- Generate a complete test file with comprehensive coverage
- Include appropriate mocks for any external dependencies
- Add clear comments explaining complex test scenarios
Create the test file at the appropriate location following project conventions.