Skip to main content
commandsSource-backedReview first Safety Privacy

Generate Tests Custom Command

A user-created custom slash command for Claude Code that turns a file or function into a test suite. You create .claude/commands/generate-tests.md and invoke it with /generate-tests; it is a prompt recipe, not a built-in command, and uses no CLI flags.

by JSONbored·added 2025-09-16·
HarnessClaude Code
Invocation:Create .claude/commands/generate-tests.md, then run: /generate-tests src/utils/discount.js
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://code.claude.com/docs/en/slash-commands, https://github.com/JSONbored/awesome-claude/blob/main/content/commands/generate-tests.mdx
Safety notes
The recipe asks Claude to run the test suite, which executes project code and test commands locally; review the source and tests before running, especially in an unfamiliar repository., If you add an allowed-tools field (e.g. Bash(npm test:*)), Claude can run those tool calls without a per-use permission prompt while the command is active. Scope it narrowly., Project-level .claude/commands files are shared via git and run for anyone who trusts the workspace; treat a checked-in command as executable content and review it before trusting the repo.
Privacy notes
Dynamic-injection lines (!`...`) and @file references send the output of shell commands and the contents of referenced files into the model context; avoid pointing them at files containing secrets, credentials, or other sensitive data.
Author
JSONbored
Claim status
unclaimed
Last verified
2025-09-16

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

78

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Complete

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    Registry metadata indicates a reviewed listing.

    Done

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

Copy & paste

Copy-ready — paste the snippet to get started.

Install command

Not provided

Config snippet

Not provided

Copy snippet

Provided

Prerequisites

None

Platforms

1 listed

Difficulty

100/100

Adoption plan

Balanced adoption plan

Current risk score 16/100. Use staged verification before broader rollout.

Risk 16

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    Listing has review metadata.

    Done
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Required evidence gates are covered (5/6 signals complete).

Risk 15

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Present

Review metadata is present.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required evidence gates are covered for this preset.

Decision timeline

Decision timeline · balanced

5/6 steps complete with no blocking gaps for this preset.

Risk 14

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is available.

Done

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

No required blockers for this timeline preset.

Safety & privacy surface

Safety & privacy surface

3 safety and 1 privacy notes across 4 risk areas. Review closely: credentials & tokens, permissions & scopes.

4 areas
  • SafetyExecution & processesThe recipe asks Claude to run the test suite, which executes project code and test commands locally; review the source and tests before running, especially in an unfamiliar repository.
  • SafetyPermissions & scopesIf you add an allowed-tools field (e.g. Bash(npm test:*)), Claude can run those tool calls without a per-use permission prompt while the command is active. Scope it narrowly.
  • SafetyLocal filesProject-level .claude/commands files are shared via git and run for anyone who trusts the workspace; treat a checked-in command as executable content and review it before trusting the repo.
  • PrivacyCredentials & tokensDynamic-injection lines (!`...`) and @file references send the output of shell commands and the contents of referenced files into the model context; avoid pointing them at files containing secrets, credentials, or other sensitive data.

Safety notes

  • The recipe asks Claude to run the test suite, which executes project code and test commands locally; review the source and tests before running, especially in an unfamiliar repository.
  • If you add an allowed-tools field (e.g. Bash(npm test:*)), Claude can run those tool calls without a per-use permission prompt while the command is active. Scope it narrowly.
  • Project-level .claude/commands files are shared via git and run for anyone who trusts the workspace; treat a checked-in command as executable content and review it before trusting the repo.

Privacy notes

  • Dynamic-injection lines (!`...`) and @file references send the output of shell commands and the contents of referenced files into the model context; avoid pointing them at files containing secrets, credentials, or other sensitive data.

Schema details

Install type
copy
Reading time
5 min
Difficulty score
100
Troubleshooting
Yes
Breaking changes
No
Skill and platform metadata
Retrieval sources
https://code.claude.com/docs/en/slash-commandshttps://code.claude.com/docs/en/common-workflowshttps://jestjs.io/docs/getting-startedhttps://docs.pytest.org/en/stable/
Runtime and command metadata
Command syntax
Create .claude/commands/generate-tests.md, then run: /generate-tests src/utils/discount.js
Full copyable content
mkdir -p .claude/commands && printf -- '---\ndescription: Generate a test suite for the given file or function\nargument-hint: [file-or-function]\n---\nWrite a thorough test suite for $ARGUMENTS. Match the project'\''s existing test framework and conventions, cover the happy path, edge cases, and error handling, and run the tests.\n' > .claude/commands/generate-tests.md

About this resource

There is no built-in /generate-tests (or /test-gen) command in Claude Code, and custom slash commands do not accept CLI-style flags such as --unit, --jest, or --threshold=90. This page describes how to build generate-tests yourself as a custom slash command — a small Markdown prompt recipe you save in your project — following the official Claude Code slash commands / skills documentation.

A custom command is just a Markdown file. The command name comes from the filename: a file at .claude/commands/generate-tests.md creates /generate-tests. (Custom commands have been merged into skills; a skill at .claude/skills/generate-tests/SKILL.md produces the same /generate-tests and is the newer, recommended form, but existing .claude/commands/*.md files keep working identically.)

Where the file lives

Scope Location Available in
Project (shared via git) .claude/commands/generate-tests.md This repository
Personal (all your projects) ~/.claude/commands/generate-tests.md Every project on your machine

The command name is the filename without the .md extension. Subdirectories namespace the command (for example .claude/commands/test/unit.md is invoked as /test:unit).

Create the command

mkdir -p .claude/commands

Save this to .claude/commands/generate-tests.md:

---
description: Generate a test suite for the given file or function
argument-hint: [file-or-function]
---

Write a thorough automated test suite for $ARGUMENTS.

- Detect and match the project's existing test framework and conventions
  (look for jest.config.*, vitest.config.*, pytest.ini, pyproject.toml,
  go.mod, etc.). Do not introduce a new framework unless none exists.
- Cover the happy path, edge cases (empty/zero/boundary values), and
  error handling.
- Place tests next to existing tests, following the current naming pattern.
- After writing, run the test command and fix any failures.

The $ARGUMENTS placeholder is replaced with whatever you type after the command name. The description and argument-hint frontmatter fields drive the autocomplete UI. These are the real frontmatter fields documented for custom commands/skills — there are no test-type or framework flags.

Invoke it

/generate-tests src/utils/discount.js
/generate-tests "the calculateDiscount function in pricing.ts"

Because the behavior is plain prompt text, you steer test type and framework by what you write in the recipe or in your arguments, not via flags. For example, you can keep one recipe and ask for a specific style at call time:

/generate-tests src/api/users.py — focus on integration tests with pytest fixtures

Or maintain several focused recipes (.claude/commands/test/unit.md, .claude/commands/test/integration.md, .claude/commands/test/edge-cases.md) and call /test:unit, /test:integration, etc.

Optional: pre-run context with dynamic injection

Custom commands support a documented preprocessing syntax. A line beginning with !`<command>` runs the shell command and inlines its output into the prompt before Claude reads it, and @path/to/file includes a file's contents. This lets the recipe hand Claude the source under test automatically:

---
description: Generate a test suite for the given file
argument-hint: [file]
allowed-tools: Bash(npm test:*), Bash(pytest:*)
---

Existing test layout:
!`ls -R tests __tests__ 2>/dev/null | head -40`

Source to test:
@$ARGUMENTS

Write a thorough test suite for the file above, matching existing conventions,
then run the tests.

allowed-tools grants the listed tools without a per-call permission prompt while the command is active; it does not restrict Claude's other tools. Shell-injection lines (!`...`) can be disabled org-wide with "disableSkillShellExecution": true in settings.

Example: what a generated suite looks like

Given a JavaScript function:

function calculateDiscount(price, discountPercentage, customerType) {
  if (price <= 0) throw new Error("Price must be positive");
  if (discountPercentage < 0 || discountPercentage > 100) {
    throw new Error("Discount must be between 0 and 100");
  }
  const baseDiscount = price * (discountPercentage / 100);
  const multiplier = customerType === "premium" ? 1.2 : 1;
  return Math.min(baseDiscount * multiplier, price * 0.5);
}

/generate-tests src/pricing.js might produce a Jest suite:

describe("calculateDiscount", () => {
  test("calculates a basic discount", () => {
    expect(calculateDiscount(100, 10, "regular")).toBe(10);
  });
  test("applies the premium multiplier", () => {
    expect(calculateDiscount(100, 10, "premium")).toBe(12);
  });
  test("caps the discount at 50% of price", () => {
    expect(calculateDiscount(100, 60, "premium")).toBe(50);
  });
  test("throws on non-positive price", () => {
    expect(() => calculateDiscount(-10, 10, "regular")).toThrow(
      "Price must be positive",
    );
  });
  test("throws on out-of-range discount", () => {
    expect(() => calculateDiscount(100, 105, "regular")).toThrow(
      "Discount must be between 0 and 100",
    );
  });
});

For Python projects the same recipe yields pytest tests using fixtures and @pytest.mark.parametrize. The framework is chosen by matching your project, not by a flag.

When to use it

Reach for a generate-tests recipe when you repeatedly ask Claude to scaffold tests and want a consistent, project-aware prompt one keystroke away. For one-off test generation you can just ask in chat — the custom command pays off when the instructions (framework detection, naming conventions, coverage expectations, run-and-fix loop) are stable enough to codify.

Notes

  • This is a user-authored recipe, not an official command. There is no guaranteed coverage threshold, no --mutation/--property-based switch, and no built-in report generation; you get whatever you ask the prompt to produce.
  • Generated tests are a starting point. Review them and run the suite yourself before relying on them.

Source citations

Add this badge to your README

Show that Generate Tests Custom Command is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/commands/generate-tests.svg)](https://heyclau.de/entry/commands/generate-tests)

How it compares

Generate Tests Custom Command side by side with 2 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

Next steps differ across entries — use the actions in the table below to copy install commands and source links per resource.

Field

A user-created custom slash command for Claude Code that turns a file or function into a test suite. You create .claude/commands/generate-tests.md and invoke it with /generate-tests; it is a prompt recipe, not a built-in command, and uses no CLI flags.

Open dossier

User-created Claude Code custom slash command recipe for planning deeper tests around a file or function, including edge cases, property-style invariants, regression cases, and mutation-score gaps where the project already supports those tools.

Open dossier

A user-created custom slash command that runs a red-green-refactor TDD loop in Claude Code: write failing tests first, implement until they pass, then refactor. Built with the documented custom-command frontmatter and $ARGUMENTS substitution, not a built-in feature.

Open dossier
Next stepsDiffers
Trust
Review statusReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewed
Package trustPackage not verifiedPackage not verifiedPackage not verified
Source provenanceSource-backedSource-backedSource-backed
Submitter
Install riskReview firstReview firstReview first
Notes Safety Privacy Safety Privacy Safety Privacy
Brand
Categorycommandscommandscommands
Sourcesource-backedsource-backedsource-backed
AuthorJSONboredJSONboredJSONbored
Added2025-09-162025-09-162025-10-25
Platforms
Claude Code
Claude Code
Claude Code
Source repo
Safety notesThe recipe asks Claude to run the test suite, which executes project code and test commands locally; review the source and tests before running, especially in an unfamiliar repository. If you add an allowed-tools field (e.g. Bash(npm test:*)), Claude can run those tool calls without a per-use permission prompt while the command is active. Scope it narrowly. Project-level .claude/commands files are shared via git and run for anyone who trusts the workspace; treat a checked-in command as executable content and review it before trusting the repo.This recipe asks Claude to inspect and draft tests against local project code; review generated tests before committing them. Run the narrowest relevant test command yourself and verify failures before broadening the suite or changing production code. If you add allowed-tools or dynamic shell injection to the command file, scope those permissions narrowly because the command can run local tools.The base recipe does not pre-approve Bash commands. Review the project's test scripts first, then approve the exact test command when Claude Code prompts or add a narrowly scoped command only after you trust it. Claude may create and edit test and source files as part of the loop (Read/Edit/Write). Run it in version control so changes are reviewable and reversible. If you extend the prompt with auto-commit or deploy steps, add explicit safety review; the base recipe does not commit or push.
Privacy notesDynamic-injection lines (!`...`) and @file references send the output of shell commands and the contents of referenced files into the model context; avoid pointing them at files containing secrets, credentials, or other sensitive data.The target source file, nearby tests, failures, logs, and command arguments may be sent into the model context. Use synthetic fixtures and redacted logs; do not paste production data, credentials, customer records, or private incident details into generated tests.The command body can read project files via @ references and !`command` injection if you add them; only reference files you are comfortable sending to the model as prompt context. The base recipe asks you to inspect project test scripts instead of injecting package.json automatically.
Prerequisites— none listed— none listed— none listed
Install
/test-advanced src/utils/parser.ts
Config
Citations
ClaimUnclaimedUnclaimedUnclaimed
Open 3 picks in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.