Skip to content
Back to skills

Add Backend Testing

ASecurity

Add backend integration testing with Vitest to an existing app. Sets up isolated test database schema and writes tests for tRPC routers.

  • 666 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 2, 2026
ai-agentstypescriptgobashsqltestinggitapidatabasebackend

Works with

  • api
  • mcp

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 2, 2026

npx -y skills add majiayu000/claude-skill-registry --skill add-backend-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Add Backend Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Add Backend Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-add-backend-testing-claude-skill-registry/badge)](https://www.skillsdirectory.com/skills/majiayu000-add-backend-testing-claude-skill-registry)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: add-backend-testing
description: 'Add backend integration testing with Vitest to an existing app. Sets up isolated test database schema and writes tests for tRPC routers.'
---

# Add Backend Testing

**Goal:** Set up backend integration testing with Vitest using an isolated test database schema.

---

## Task 1: Gather Information

Before starting, you need:
- `service_id`: The Timescale Cloud service ID for the database

If not provided, check the `DATABASE_URL` in `.env` to find it, or use `service_list` MCP tool.

---

## Task 2: Set Up Test Infrastructure

1. Use the `setup_testing` MCP tool:
   ```
   setup_testing(application_directory: ".", service_id: "<service_id>")
   ```

2. Install Vitest:
   ```bash
   npm install -D vitest dotenv
   ```

3. Add test scripts to package.json:
   ```json
   {
     "scripts": {
       "test": "vitest run",
       "test:watch": "vitest"
     }
   }
   ```

4. Write integration tests for each tRPC router using this pattern:
   ```typescript
   import { describe, it, expect } from "vitest";
   import { appRouter } from "~/server/api/root";
   import { createCallerFactory } from "~/server/api/trpc";
   import { db } from "~/server/db";

   const createCaller = createCallerFactory(appRouter);
   const caller = createCaller({ session: null, db, headers: new Headers() });

   describe("exampleRouter", () => {
     it("returns data", async () => {
       const result = await caller.example.getAll();
       expect(result).toBeDefined();
     });
   });
   ```

5. Run `npm test` and ensure all tests pass before completing

---

## Task 3: Update CLAUDE.md

Add a Testing section to CLAUDE.md with the following content:

```markdown
## Testing

This app uses Vitest for backend integration testing with an isolated test database schema.

**Test infrastructure:**
- Tests run against a separate PostgreSQL schema (see `DATABASE_SCHEMA` in `.env.test.local`)
- A dedicated test user has permissions only on the test schema
- Schema is automatically pushed before tests via global setup
- Tests use `.env.test.local` for database configuration (gitignored)

**Writing tests:**
\`\`\`typescript
import { describe, it, expect } from "vitest";
import { appRouter } from "~/server/api/root";
import { createCallerFactory } from "~/server/api/trpc";
import { db } from "~/server/db";

const createCaller = createCallerFactory(appRouter);
const caller = createCaller({ session: null, db, headers: new Headers() });

describe("myRouter", () => {
  it("returns data", async () => {
    const result = await caller.my.getData();
    expect(result).toBeDefined();
  });
});
\`\`\`
```

Also update:
- Add `npm test` and `npm run test:watch` to the Commands section
- Add "3. Add tests in `src/test/routers`" to the "New tRPC Router" checklist
- Update "Before Committing" section to include `npm test`:
  ```bash
  npm test && npm run check
  ```

---

## Task 4: Commit

Ask the user if they want to commit the changes.

---

## Task 5: Offer Further Hardening

Ask the user: "Would you like to add stricter TypeScript checks as well? This catches additional bugs that standard TypeScript misses."

If yes, follow the `add-strict-checks` skill.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.