test-generator
Skill3 starsChanged 9 months agoMITView on GitHub
Generate unit and integration tests for API routes, utilities, React components, and hooks. Use when asked to generate tests, write unit tests, create integration tests, add test coverage, or test a component/route/function.
25 other projects use a version of this.
Adopted by
Most recently taken up by
- u9401066/zotero-keepertheir own version, first seen Nov 8, 2026
- Data-Wise/crafttheir own version, first seen Oct 31, 2026
- u9401066/pubmed-search-mcptheir own version, first seen Oct 20, 2026
- aidankaokao/claude-skillstheir own version, first seen Oct 9, 2026
- jablonkai/skillstheir own version, first seen Oct 1, 2026
- Ecoa-PUC-Rio/GAIDEtheir own version, first seen Aug 19, 2026
Used with
Projects with it also use refactor-advisor, log-analyzer and 3 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
aidankaokaoSkillrefactor-advisor
分析程式碼的重構機會,給出有優先順序的建議,但不直接改寫程式碼。當使用者說「這段程式碼怎麼改比較好」、「幫我分析重構方向」、「這樣寫有什麼問題」、「refactor」、「技術債」時觸發。
Also in 3 projects that use this
nek1987Skilllog-analyzer
Parse and analyze application logs to identify errors, patterns, and insights.
Also in 3 projects that use this
JeffallanSkillsecurity-reviewer
Identifies security vulnerabilities, generates structured audit reports with severity ratings, and provides actionable remediation guidance. Use when conducting security audits, reviewing code for vulnerabilities, or analyzing infrastructure security. Invoke for SAST scans, penetration testing, DevSecOps practices, cloud security reviews, dependency audits, secrets scanning, or compliance checks. Produces vulnerability reports, prioritized recommendations, and compliance checklists.
Also in 3 projects that use this
Microsoft AzureSkillgit-workflow
Squad branching model: dev-first workflow with insiders preview channel
Also in 3 projects that use this
GoogleSkillcode-review
Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.
Also in 4 projects that use this
Other versions25 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 25
- laolaoshiren/claude-code-skills-zh★ 907same name
- u9401066/pubmed-search-mcp★ 28same name
- Ecoa-PUC-Rio/GAIDE★ 8same name
- jcarlos78/GAIDE★ 8same name
- u9401066/zotero-keeper★ 7same name
- bestdeejay-design/agent-skills★ 6same name
- Data-Wise/craft★ 4same name
- u9401066/nsforge-mcp★ 4same name
- suxiao1824308603/Qoder-devtools-skills★ 3same name
- u9401066/template-is-all-you-need★ 3same name
15 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- ai-integration-generatorSkill
- api-docs-generatorSkill
- auth-scaffoldSkill
- code-reviewerSkill
- db-seed-generatorSkill
- env-config-validatorSkill
- error-boundary-generatorSkill
- git-commit-composerSkill
- nextjs-middleware-generatorSkill
- nextjs-route-generatorSkill
- prisma-migration-reviewerSkill
- prisma-query-optimizerSkill
- react-component-generatorSkill
- typescript-refactorerSkill
- zod-schema-generatorSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 2 are distinctive, and 5 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Before generating any output, read config/defaults.md and adapt all patterns, imports, and code examples to the user's configured stack.
- Distinctive: line 12
Read the source file to understand its exports, dependencies, and behavior.
- Distinctive: line 15
Write the test file using Vitest syntax (fall back to Jest if the project uses it).
- Very specific: line 20
Place test file adjacent to source: foo.ts → foo.test.ts, Foo.tsx → Foo.test.tsx.
- Very specific: line 21
If the project uses a __tests__/ directory convention, follow that instead.
- Very specific: line 154
Use React Testing Library.
- Very specific: line 301
Use descriptive names following the pattern: should [expected behavior] when [condition].
“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Test Generator
Before generating any output, read config/defaults.md and adapt all patterns, imports, and code examples to the user's configured stack.
Process
- Read the source file to understand its exports, dependencies, and behavior.
- Identify the source type: API route, utility function, React component, or hook.
- Generate test cases covering: happy path, edge cases, error handling, boundary values.
- Write the test file using Vitest syntax (fall back to Jest if the project uses it).
- Include proper mocking, setup/teardown, and descriptive test names.
File Naming and Placement
- Place test file adjacent to source:
foo.ts→foo.test.ts,Foo.tsx→Foo.test.tsx. - If the project uses a
__tests__/directory convention, follow that instead. - For API route tests:
app/api/users/route.ts→app/api/users/route.test.ts.
Testing API Routes
Analyze the route handler and generate tests for each HTTP method.
// Source: app/api/users/route.ts (POST handler)
// Test: app/api/users/route.test.ts
import { describe, it, expect, vi, beforeEach } from "vitest";
import { POST } from "./route";
import { prisma } from "@/lib/prisma";
vi.mock("@/lib/prisma", () => ({
prisma: {
user: {
create: vi.fn(),
findUnique: vi.fn(),
},
},
}));
describe("POST /api/users", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("should create a user and return 201", async () => {
const mockUser = { id: "1", email: "test@example.com", name: "Test" };
vi.mocked(prisma.user.create).mockResolvedValue(mockUser);
const request = new Request("http://localhost/api/users", {
method: "POST",
body: JSON.stringify({ email: "test@example.com", name: "Test" }),
});
const response = await POST(request);
const data = await response.json();
expect(response.status).toBe(201);
expect(data).toEqual(mockUser);
});
it("should return 400 when email is missing", async () => {
const request = new Request("http://localhost/api/users", {
method: "POST",
body: JSON.stringify({ name: "Test" }),
});
const response = await POST(request);
expect(response.status).toBe(400);
});
it("should return 409 when email already exists", async () => {
vi.mocked(prisma.user.create).mockRejectedValue(
new Error("Unique constraint failed on the fields: (`email`)")
);
const request = new Request("http://localhost/api/users", {
method: "POST",
body: JSON.stringify({ email: "taken@example.com", name: "Test" }),
});
const response = await POST(request);
expect(response.status).toBe(409);
});
it("should return 500 on unexpected error", async () => {
vi.mocked(prisma.user.create).mockRejectedValue(new Error("DB down"));
const request = new Request("http://localhost/api/users", {
method: "POST",
body: JSON.stringify({ email: "test@example.com", name: "Test" }),
});
const response = await POST(request);
expect(response.status).toBe(500);
});
});API Route Test Checklist
- Each HTTP method has at least one happy path test
- Invalid request body returns 400
- Missing/invalid auth returns 401
- Forbidden access returns 403
- Resource not found returns 404
- Duplicate/conflict returns 409
- Unexpected errors return 500 (not leak stack traces)
Testing Utility Functions
Focus on pure logic, null/undefined handling, and thrown errors.
// Source: lib/utils/slugify.ts
// Test: lib/utils/slugify.test.ts
import { describe, it, expect } from "vitest";
import { slugify } from "./slugify";
describe("slugify", () => {
it("should convert a simple string to slug", () => {
expect(slugify("Hello World")).toBe("hello-world");
});
it("should handle special characters", () => {
expect(slugify("Héllo & Wörld!")).toBe("hello-world");
});
it("should collapse multiple hyphens", () => {
expect(slugify("foo---bar")).toBe("foo-bar");
});
it("should trim leading and trailing hyphens", () => {
expect(slugify("-hello-")).toBe("hello");
});
it("should return empty string for empty input", () => {
expect(slugify("")).toBe("");
});
it("should handle null/undefined gracefully", () => {
expect(slugify(null as unknown as string)).toBe("");
});
});Testing React Components
Use React Testing Library. Prefer getByRole over getByTestId.
// Test: components/LoginForm.test.tsx
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { LoginForm } from "./LoginForm";
describe("LoginForm", () => {
it("should render email and password fields", () => {
render(<LoginForm onSubmit={vi.fn()} />);
expect(screen.getByRole("textbox", { name: /email/i })).toBeInTheDocument();
expect(screen.getByLabelText(/password/i)).toBeInTheDocument();
});
it("should call onSubmit with form values", async () => {
const user = userEvent.setup();
const onSubmit = vi.fn();
render(<LoginForm onSubmit={onSubmit} />);
await user.type(screen.getByRole("textbox", { name: /email/i }), "a@b.com");
await user.type(screen.getByLabelText(/password/i), "secret123");
await user.click(screen.getByRole("button", { name: /sign in/i }));
expect(onSubmit).toHaveBeenCalledWith({
email: "a@b.com",
password: "secret123",
});
});
it("should show validation error for invalid email", async () => {
const user = userEvent.setup();
render(<LoginForm onSubmit={vi.fn()} />);
await user.type(screen.getByRole("textbox", { name: /email/i }), "bad");
await user.click(screen.getByRole("button", { name: /sign in/i }));
expect(screen.getByRole("alert")).toHaveTextContent(/valid email/i);
});
it("should disable submit button while loading", () => {
render(<LoginForm onSubmit={vi.fn()} isLoading />);
expect(screen.getByRole("button", { name: /sign in/i })).toBeDisabled();
});
});Component Test Checklist
- Renders without crashing
- Displays correct content based on props
- Interactive elements respond to user events
- Conditional rendering works for all states (loading, error, empty, success)
- Accessible: interactive elements have roles and labels
- Form submission calls handler with correct values
- Error states display properly
Testing Hooks
Wrap custom hooks with renderHook from React Testing Library.
// Test: hooks/useDebounce.test.ts
import { describe, it, expect, vi } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { useDebounce } from "./useDebounce";
describe("useDebounce", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it("should return initial value immediately", () => {
const { result } = renderHook(() => useDebounce("hello", 500));
expect(result.current).toBe("hello");
});
it("should debounce value updates", () => {
const { result, rerender } = renderHook(
({ value }) => useDebounce(value, 500),
{ initialProps: { value: "hello" } }
);
rerender({ value: "world" });
expect(result.current).toBe("hello"); // not yet updated
act(() => { vi.advanceTimersByTime(500); });
expect(result.current).toBe("world"); // now updated
});
it("should cancel previous timer on rapid updates", () => {
const { result, rerender } = renderHook(
({ value }) => useDebounce(value, 500),
{ initialProps: { value: "a" } }
);
rerender({ value: "b" });
act(() => { vi.advanceTimersByTime(300); });
rerender({ value: "c" });
act(() => { vi.advanceTimersByTime(500); });
expect(result.current).toBe("c"); // skipped "b"
});
});Mocking Patterns
Mock a module
vi.mock("@/lib/prisma", () => ({
prisma: { user: { findMany: vi.fn() } },
}));Mock next/navigation
vi.mock("next/navigation", () => ({
useRouter: () => ({ push: vi.fn(), back: vi.fn() }),
useSearchParams: () => new URLSearchParams("q=test"),
usePathname: () => "/dashboard",
}));Mock fetch
const mockFetch = vi.fn();
global.fetch = mockFetch;
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ data: "test" }),
});Test Naming Convention
Use descriptive names following the pattern: should [expected behavior] when [condition].
should return 401 when auth token is missingshould render loading spinner when data is fetchingshould throw TypeError when input is not a string
Output Format
## Generated Tests
**Source**: `path/to/source.ts`
**Test file**: `path/to/source.test.ts`
**Framework**: Vitest
### Test Cases
| # | Test | Category |
|---|------|----------|
| 1 | should ... | Happy path |
| 2 | should ... | Edge case |
| 3 | should ... | Error handling |
[Generated code block]
### Coverage Notes
- [Any areas that need additional manual test cases]Verification Loop
After generating tests, run them with the project's test runner. If any test fails due to a generation error (not a legitimate bug), analyze the failure, fix the test, and re-run. Repeat up to 3 times. If a test fails because it caught a real bug in the source code, flag it clearly in the output: REAL BUG FOUND: [description]. Only deliver tests that either pass or explicitly flag real bugs.
Reference
See references/testing-patterns.md for Vitest setup, Prisma mocking, and MSW patterns.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

