Skip to main content

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

  1. Go to Settings in the sidebar → Automation
  2. Toggle Auto-Generate Tests on

The .codepeel.yml setting takes priority if both are configured.


How It Works

  1. CodePeel completes the normal review of your PR
  2. Analyzes the diff to identify changed functions, classes, and modules
  3. Generates appropriate unit tests for new/modified code
  4. Creates a new branch: codepeel/tests-pr-{number}-{timestamp}
  5. Opens a PR targeting your feature branch (so tests merge with your code)
  6. Posts a comment on your original PR linking to the test PR

What Gets Generated

Change typeTests generated
New functionsUnit tests for each public function
New API routesIntegration tests for request/response
Modified logicRegression tests for changed behavior
Edge casesBoundary 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