# Test Generator

Automatically suggest tests for new functions and components.

- Repository: https://github.com/alirezarezvani/claude-code-tresor (782 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-07-03
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add alirezarezvani/claude-code-tresor --skill test-generator -g -a claude-code -y`
Codex: `npx skills add alirezarezvani/claude-code-tresor --skill test-generator -g -a codex -y`
Cursor: `npx skills add alirezarezvani/claude-code-tresor --skill test-generator -g -a cursor -y`
Gemini CLI: `npx skills add alirezarezvani/claude-code-tresor --skill test-generator -g -a gemini-cli -y`

## Description

Automatically suggest tests for new functions and components. Use when new code is written, functions added, or user mentions testing. Creates test scaffolding with Jest, Vitest, Pytest patterns. Triggers on new functions, components, test requests, testing mentions.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Test Generator Skill

Auto-suggest tests when you write new code.

## When I Activate

- ✅ New function created
- ✅ New component added
- ✅ User mentions testing or tests
- ✅ Test file missing for implementation
- ✅ User asks "can you test this?"

## What I Generate

### Quick Test Scaffolding
- Basic happy path tests
- Null/undefined edge cases
- Simple error scenarios
- Framework-appropriate syntax (Jest/Vitest/Pytest)

### What I Don't Do
- Comprehensive test suites → Use **@test-engineer** sub-agent
- Integration tests → Use **@test-engineer** sub-agent
- E2E test design → Use **@test-engineer** sub-agent
- Test strategy planning → Use **@test-engineer** sub-agent

## Relationship with @test-engineer Sub-Agent

**Me (Skill):** Quick test scaffolding
**@test-engineer (Sub-Agent):** Comprehensive testing strategy

### Workflow
1. You write a function
2. I auto-generate basic test structure
3. You want full suite → Invoke **@test-engineer** sub-agent
4. Sub-agent creates comprehensive tests

## Examples

### JavaScript Function

```javascript
// You write:
function calculateDiscount(price, percentage) {
  if (price <= 0) throw new Error('Invalid price');
  return price * (percentage / 100);
}

// I auto-generate:
describe('calculateDiscount', () => {
  it('calculates discount correctly', () => {
    expect(calculateDiscount(100, 10)).toBe(10);
  });

  it('throws error for invalid price', () => {
    expect(() => calculateDiscount(0, 10)).toThrow('Invalid price');
  });

  it('handles zero percentage', () => {
    expect(calculateDiscount(100, 0)).toBe(0);
  });

  // TODO: Add more edge cases
  // Consider: negative percentages, decimal values, very large numbers
});
```

### React Component

```jsx
// You write:
function UserCard({ user, onEdit }) {
  return (
    <div className="user-card">
      <h2>{user.name}</h2>
      <button onClick={() => onEdit(user.id)}>Edit</button>
    </div>
  );
}

The rest: https://github.com/alirezarezvani/claude-code-tresor/blob/HEAD/skills/development/test-generator/SKILL.md
