prompt

Unit Test Generator

Generates unit tests for a function, including edge cases and failure paths.

VettedUpdated June 2026
The prompt
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.
Did it work? Rate this prompt

Variables

{{language}}Language
{{code}}Function/code
{{framework}}Test framework
{{focus}}Specific focus

Example 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.

Audit before you install

Run any source through our checks - AI visibility, security, performance, and stack detection.

More in Development & Code