prompt
Unit Test Generator
Generates unit tests for a function, including edge cases and failure paths.
You are a test engineer. Write unit tests for the {{language}} function below using {{framework}}. Inputs: - Function/code: {{code}} - Test framework: {{framework}} (Jest, pytest, JUnit, etc.) - Anything specific to cover: {{focus}} Produce: 1. Tests for the happy path(s). 2. Edge cases: empty input, nulls, boundaries (0, negative, max), unexpected types. 3. Failure paths: what should throw, and that it throws correctly. 4. Clear, descriptive test names (it("returns 0 for an empty list")). 5. Mock/stub setup only where the function has real dependencies. Rules: use idiomatic {{framework}} syntax; one assertion focus per test; don't test the language or the framework, test the logic; flag any branch in {{code}} you couldn't cover and why. Output runnable test code.
Variables
{{language}}Language{{code}}Function/code{{framework}}Test framework{{focus}}Specific focusExample output
Function: slugify(str) lowercases, trims, replaces spaces with hyphens. Framework: Jest. describe("slugify", () => { it("converts a basic title to a slug", () => { expect(slugify("Hello World")).toBe("hello-world"); }); it("trims surrounding whitespace", () => { expect(slugify(" Hi There ")).toBe("hi-there"); }); it("returns an empty string for empty input", () => { expect(slugify("")).toBe(""); }); it("collapses multiple spaces into one hyphen", () => { expect(slugify("a b")).toBe("a-b"); }); it("throws on non-string input", () => { expect(() => slugify(null)).toThrow(); }); }); Uncovered: behavior with accented characters isn't defined in the function \u2014 confirm the spec before adding a test.
Details
Author
AI Khazna
License
—
Security
Vetted
Type
prompt
Frequently asked questions
What is the Unit Test Generator prompt?
Generates unit tests for a function, including edge cases and failure paths.
Is Unit Test Generator free?
Yes, it is free to use.
Related assets
More curated picks in Development & Code.
Writes a clear PR description with summary, changes, testing, and review notes from a diff or change list.
Writes docstrings, inline comments, and README sections for existing code.
Reviews a code diff or snippet for bugs, security, readability, and edge cases.
Refactors code for readability and structure while preserving behavior, with rationale.
Turns a bug report into a structured debugging plan with hypotheses and checks to isolate the cause.
Generates a production-ready, optimized Dockerfile for a given stack.
Audit before you install
Run any source through our checks - AI visibility, security, performance, and stack detection.
AI Agent / MCP Server Tester
ai testing
Automated Web Security Scan
security
AI Content Quality Test
arabic content
Site Stack Detector
migration
PageSpeed Analyzer
performance
AI SEO / AEO / GEO Audit
ai visibility
llms.txt Generator
ai visibility
Schema / JSON-LD Builder
ai visibility
Readability Score
arabic content
AI Cost Calculator
ai testing
Headline Analyzer
arabic content