generate-unit-test

generate-unit-test is a cursor rule for coding agents from holasoymalva/AI-Unit-Test-Builder. It costs 8 tokens per session (1,539 once invoked), scanned A, original, MIT.

A rule for generating unit tests, which test individual functions in isolation, from a prior analysis of those functions.

In plain words
What is it for?
It helps create test files, mocks, setup code, and tests for functions using frameworks such as Jest or Vitest.
Why use it?
It reduces the chance of missing normal, edge-case, and error scenarios when writing tests.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/holasoymalva/ai-unit-test-builder/generate-unit-test
Clone the repo
git clone --depth 1 https://github.com/holasoymalva/AI-Unit-Test-Builder

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for generate-unit-test

README.md
[![agentmods](https://agentmods.dev/badge/rules/holasoymalva/ai-unit-test-builder/generate-unit-test.svg)](https://agentmods.dev/rules/holasoymalva/ai-unit-test-builder/generate-unit-test)
Your own site
<a href="https://agentmods.dev/rules/holasoymalva/ai-unit-test-builder/generate-unit-test"><img src="https://agentmods.dev/badge/rules/holasoymalva/ai-unit-test-builder/generate-unit-test.svg" alt="Measured on agentmods" height="20"></a>
Per session 8 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,539 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00008 $0.01539
Opus 5 $0.00004 $0.00770
Sonnet 5 $0.00002 $0.00308
Haiku 4.5 $0.00001 $0.00154

Measured 4d ago against content hash 5f17b761449c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

generate-unit-test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

mdc/generate-unit-test.mdc · 275 lines

How it starts

The opening of the file, as written. The whole thing — 275 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Rule: Unit Test Generation

Goal

To guide an AI assistant in generating comprehensive unit tests based on a previously created function analysis document. The tests should cover all scenarios identified in the analysis and follow testing best practices.

Prerequisites

  • A function analysis document (created by extract-functions.mdc)
  • Source code file to be tested
  • Knowledge of the testing framework being used (Jest, Vitest, etc.)

Process

  1. Load Analysis Document: Read and understand the function analysis document
  2. Identify Testing Framework: Determine the testing framework and setup requirements
  3. Generate Test Structure: Create the basic test file structure with imports and setup
  4. Generate Function Tests: Create comprehensive tests for each function based on the analysis
  5. Add Mock Implementations: Generate necessary mocks and test utilities
  6. Save Test File: Save as [source-filename].test.[extension] alongside the source file

Test Generation Guidelines

Test File Structure

// Imports and setup
import { function1, function2 } from './source-file';
import { jest } from '@jest/globals'; // or equivalent for your framework

// Mock setup (if needed)
jest.mock('external-dependency');

// Test setup and utilities
const mockSetup = () => { /* setup code */ };

// Test suites grouped by function
describe('FunctionName', () => {
  // Tests for each function
});

For Each Function Generate:

1. Basic Test Structure
describe('[FunctionName]', () => {
  // Setup
  beforeEach(() => {
    // Reset mocks, setup test data
  });

  // Test cases here
});
2. Happy Path Tests
  • Test normal, expected usage
  • Test with typical input values
  • Verify expected return values and behavior
3. Edge Case Tests
  • Boundary values (empty strings, zero, null, undefined)
  • Maximum/minimum values
  • Special characters or unusual but valid inputs
4. Error Handling Tests
  • Invalid inputs
  • Error throwing scenarios
  • Error message validation

Read the full file on GitHub · 275 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 275 lines · 8 tokens per session scan A 5f17b761449c

Subscribe to this mod's changes

generate-unit-test is a cursor rule published in the GitHub repository holasoymalva/AI-Unit-Test-Builder (7 stars, last pushed 1y ago), licensed MIT. It adds 8 tokens to every session and 1,539 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.