Auto-Test Generation
CodePeel can generate unit tests for your PR changes and open a separate pull request with those tests.
How to Enable
Option 1: Via .codepeel.yml
auto_test:
enabled: true
Option 2: Via the Dashboard
- Go to Settings in the sidebar → Automation
- Toggle Auto-Generate Tests on
The
.codepeel.ymlsetting takes priority if both are configured.
How It Works
- CodePeel completes the normal review of your PR
- Analyzes the diff to identify changed functions, classes, and modules
- Generates appropriate unit tests for new/modified code
- Creates a new branch:
codepeel/tests-pr-{number}-{timestamp} - Opens a PR targeting your feature branch (so tests merge with your code)
- Posts a comment on your original PR linking to the test PR
What Gets Generated
| Change type | Tests generated |
|---|---|
| New functions | Unit tests for each public function |
| New API routes | Integration tests for request/response |
| Modified logic | Regression tests for changed behavior |
| Edge cases | Boundary condition tests the AI identifies |
CodePeel detects your test framework (Jest, Vitest, Mocha, etc.) and generates tests in the matching style.
Example
Your PR changes a calculateDiscount function:
export function calculateDiscount(price: number, tier: 'basic' | 'pro' | 'enterprise'): number {
const rates = { basic: 0.05, pro: 0.15, enterprise: 0.25 };
return price * (rates[tier] || 0);
}
CodePeel generates:
describe('calculateDiscount', () => {
it('applies basic tier discount', () => {
expect(calculateDiscount(100, 'basic')).toBe(5);
});
it('applies pro tier discount', () => {
expect(calculateDiscount(100, 'pro')).toBe(15);
});
it('returns 0 for zero price', () => {
expect(calculateDiscount(0, 'pro')).toBe(0);
});
});
What the Generated PR Looks Like
- Branch:
codepeel/tests-pr-{number}-{timestamp} - Title:
🤖 [CodePeel] Auto-Generated Tests for PR #{number} - Contents: Only test files — no source code changes
- Comment: A link to the test PR is posted on your original PR
Important Notes
- Auto-test is opt-in — disabled by default
- Tests are suggestions — always review before merging
- Fire-and-forget — test generation failure doesn't affect the main review
- Auto-fix and auto-test can both be enabled — they create separate PRs
← All docsCodePeel