---
title: "Unit & Integration Test Generator Prompt | Vezz me"
description: "Download the Unit & Integration Test Generator JSON preset for Vezz me. Highlight any function, class, or API handler to generate edge-case unit tests."
canonical_url: "https://vezz.me/prompts/unit-and-integration-test-generator/"
type: "pseo-prompts"
category: "prompts"
topic: "Software Engineering & Testing Preset"
intent: "Best for software developers writing robust unit and integration tests in Vitest, Jest, pytest, or Go testing."
---

# Unit & Integration Test Generator Prompt | Vezz me

Download the Unit & Integration Test Generator JSON preset for Vezz me. Highlight any function, class, or API handler to generate edge-case unit tests.

> **Best fit:** Best for software developers writing robust unit and integration tests in Vitest, Jest, pytest, or Go testing.

## Live Webpage Walkthrough

- **Source:** Backend Module — Token Bucket Rate Limiter Function (`github.com/org/gateway/blob/main/src/rateLimiter.ts`)
- **Recommended Context Mode:** Detailed

**Highlighted Passage:**
> export function consumeTokens(bucket: TokenBucket, tokens: number, nowMs: number): boolean {
  const elapsed = (nowMs - bucket.lastRefillMs) / 1000;
  bucket.currentTokens = Math.min(bucket.capacity, bucket.currentTokens + elapsed * bucket.refillRatePerSec);
  bucket.lastRefillMs = nowMs;
  if (bucket.currentTokens >= tokens) {
    bucket.currentTokens -= tokens;
    return true;
  }
  return false;
}

**User Question (Shortcut):** "Generate edge-case unit tests with Vitest for this function."

**Vezz me On-Screen Answer:**
**Edge-Case Test Matrix**:
1. Consuming when tokens are available (`true`).
2. Consuming more tokens than capacity (`false` immediately).
3. Zero tokens requested (`tokens = 0`).
4. Clock drift backwards (`nowMs < bucket.lastRefillMs`).
5. Partial fractional token accumulation.

```ts
import { describe, it, expect } from 'vitest';
import { consumeTokens } from './rateLimiter';

describe('consumeTokens', () => {
  it('should refill tokens up to capacity but not exceed it', () => {
    const bucket = { capacity: 10, currentTokens: 5, refillRatePerSec: 10, lastRefillMs: 1000 };
    expect(consumeTokens(bucket, 10, 2000)).toBe(true);
    expect(bucket.currentTokens).toBe(0);
  });

  it('should handle clock skew gracefully if nowMs is in the past', () => {
    const bucket = { capacity: 10, currentTokens: 5, refillRatePerSec: 10, lastRefillMs: 2000 };
    // If system clock jumped backwards 500ms, elapsed is negative!
    consumeTokens(bucket, 1, 1500);
    // Flag: Note that elapsed < 0 will subtract tokens in your current implementation!
  });
});
```

**Suggested Follow-Ups:**
- "Did you spot a bug with negative elapsed time if the server clock drifts backwards?"
- "Show how to fix the clock-drift bug in the source code."

## Custom Prompt Preset for Vezz me

- **Preset Name:** Unit & Integration Test Generator
- **Recommended Context Level:** Detailed
- **JSON Preset Download:** https://vezz.me/prompts/presets/unit-and-integration-test-generator.json

```text
Act as a Principal Software Engineer writing production tests for the selected code: 1) Edge-Case Matrix: identify boundary values, off-by-one errors, empty arrays/null inputs, network timeouts, and concurrency races, 2) Test Suite: write clean, self-contained test cases (using Vitest/Jest for TS/JS, pytest for Python, or testing for Go) with descriptive test names ('should return 400 when X is empty'), and 3) Mocking Guidance: mock external I/O cleanly without over-mocking internal business logic.
```

**Why it works:** Focuses on boundary edge cases (empty strings, zero, negative numbers, network timeouts, concurrent retries) rather than repetitive happy-path tests.

## Step-by-step workflow

1. **Download and import the JSON preset**: Save `unit-and-integration-test-generator.json` and import it into Vezz me.
2. **Highlight any function or API route handler on GitHub or docs**: Select the implementation and press your shortcut (default: Ctrl+Shift+X).
3. **Copy the test suite into your test file**: Paste the generated test cases directly into your codebase and run `npm test` or `pytest`.

## Tests that actually catch production bugs

Testing trivial happy paths gives high code coverage without protecting against real production failures.

- Tests boundary numbers ($0$, $-1$, `MAX_SAFE_INTEGER`, empty arrays)
- Audits time-based logic for clock-drift, timezone, and leap-second bugs
- Formats test names using standard behavior-driven naming conventions (`should ... when ...`)

## Frequently asked questions

### Can I specify my preferred testing framework in the prompt?

Yes! You can append 'using Vitest', 'using pytest', 'using Go standard library', or 'using Rust #[test]' to your query.

### Does it test asynchronous error paths?

Yes—the prompt explicitly checks for unhandled Promise rejections, timeout exceptions, and HTTP non-2xx status codes.

### Which preset should I use to review the implementation code first?

Use our Senior Engineer Code Reviewer preset.

## Related guides

- [Senior Engineer Code Reviewer Preset](https://vezz.me/prompts/senior-engineer-code-reviewer/): Review code for concurrency, security, and edge cases.
- [Explain Code Snippets & Errors](https://vezz.me/use-cases/explain-code-snippets-and-errors/): Trace unfamiliar algorithms and runtime errors line-by-line.
- [API Integration Quickstart Preset](https://vezz.me/prompts/api-integration-quickstart/): Generate typed API wrappers with built-in error handling.
- [Vezz me on GitHub](https://vezz.me/for/github/): Review PR diffs and generate test cases directly on GitHub.
