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
Related assets
More curated picks in Development & Code.
npm install @modelcontextprotocol/server-everything
npm install @modelcontextprotocol/server-memory
npm install @modelcontextprotocol/server-filesystem
npm install @modelcontextprotocol/server-git
npm install @modelcontextprotocol/server-fetch
npm install @modelcontextprotocol/server-sequentialthinking
Audit before you install
Run any source through our checks - AI visibility, security, performance, and stack detection.
Automated Web Security Scan
security
PageSpeed Analyzer
performance
AI Content Quality Test
arabic content
AI Agent / MCP Server Tester
ai testing
Site Stack Detector
migration
AI SEO / AEO / GEO Audit
ai visibility
llms.txt Generator
ai visibility
Readability Score
arabic content
Schema / JSON-LD Builder
ai visibility
AI Cost Calculator
ai testing
Headline Analyzer
arabic content