# Test Generator

> Generates unit and integration tests for a function, class, or module — covering happy path, edge cases, error cases, and boundary conditions. Supports common frameworks (Jest, Vitest, Pytest, Go testing, JUnit, RSpec). Use this skill when the user asks to "write tests for this", "add test coverage", "what tests should I add", or pastes code that lacks tests.

- Skill: `kakarot-oncloud/test-generator` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add kakarot-oncloud/test-generator`
- Raw SKILL.md: https://api.skillmd.com/api/skills/kakarot-oncloud/test-generator/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: kakarot-oncloud (https://skillmd.com/u/kakarot-oncloud)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/kakarot-oncloud/test-generator

---


# Test Generator

You generate tests that catch real bugs, not tests that just hit lines.

## Process

1. **Identify the framework.** Look for clues (`describe`, `it`, `pytest`, `func Test...`); ask if ambiguous.
2. **Read the code carefully.** Identify:
   - Public surface (what to test)
   - Inputs and their valid ranges
   - Outputs and side effects
   - Dependencies that need mocking
   - Error paths
3. **Plan the test cases** before writing — list them as a checklist first.
4. **Write the tests** following the framework's idioms.
5. **Note what you didn't cover** and why (e.g. "external API calls — mock at the network layer").

## What to cover

For every function:

- **Happy path** — typical valid input → expected output.
- **Boundaries** — empty, zero, one, max, min, just-above, just-below.
- **Invalid input** — wrong type, null, undefined, negative when positive expected.
- **Error cases** — does it throw / return error correctly?
- **Side effects** — was the DB written? Was the event emitted? Was the callback called?
- **Idempotency** — if the function claims to be idempotent, prove it.

## Test structure

Use **Arrange / Act / Assert** with clear sections:

```javascript
it('returns 0 for an empty cart', () => {
  // Arrange
  const cart = new Cart();

  // Act
  const total = cart.total();

  // Assert
  expect(total).toBe(0);
});
```

## Rules

1. **One assertion concept per test.** Multiple `expect` lines are fine if they all verify the same behavior.
2. **Test names describe behavior** — `it('returns null when user is not found')`, not `it('test getUser')`.
3. **No logic in tests.** No `if`, no loops over test cases unless using a parametrized helper.
4. **Don't test the framework or the language.** Skip tests like "constructor sets the property".
5. **Mock external dependencies** (network, filesystem, time, randomness) — but don't mock the thing under test.
6. **Use real data shapes.** If the input is a `User` object with 12 fields, build a realistic one (factory or fixture), not `{ id: 1 }`.
7. **Flag missing coverage** at the end so the user knows what's left.

## Output format

```markdown
## Test plan
- [x] empty input
- [x] valid input
- [x] invalid type
- [x] boundary at max
- [ ] not covered: timeout behavior (requires fake timers — flag for follow-up)

## Tests
<code block>

## Notes
<mocking strategy, fixtures used, anything tricky>
```

