add-backend-testing
Add backend integration testing with Vitest to an existing app. Sets up isolated test database schema and writes tests for tRPC routers.
Best use case
add-backend-testing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Add backend integration testing with Vitest to an existing app. Sets up isolated test database schema and writes tests for tRPC routers.
Teams using add-backend-testing should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/add-backend-testing/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How add-backend-testing Compares
| Feature / Agent | add-backend-testing | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Add backend integration testing with Vitest to an existing app. Sets up isolated test database schema and writes tests for tRPC routers.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 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.Related Skills
add-backend-tool
Add a new tool to the backend OpenAI function calling system. Use when user mentions "new tool", "add tool", "backend function", "agent capability", or wants to extend what the AI agent can do.
adb-device-testing
Use when testing Android apps on ADB-connected devices/emulators - UI automation, screenshots, location spoofing, navigation, app management. Triggers on ADB, emulator, Android testing, location mock, UI test, screenshot walkthrough.
act-local-testing
Use when testing GitHub Actions workflows locally with act. Covers act CLI usage, Docker configuration, debugging workflows, and troubleshooting common issues when running workflows on your local machine.
accessibility-testing
WCAG 2.2 compliance testing, screen reader validation, and inclusive design verification. Use when ensuring legal compliance (ADA, Section 508), testing for disabilities, or building accessible applications for 1 billion disabled users globally.
acceptance-testing
Plan and (when feasible) implement or execute user acceptance tests (UAT) / end-to-end acceptance scenarios. Converts requirements or user stories into acceptance criteria, test cases, test data, and a sign-off checklist; suggests automation (Playwright/Cypress for web, golden/snapshot tests for CLIs/APIs). Use when validating user-visible behavior for a release, or mapping requirements to acceptance coverage.
acc-testing-knowledge
Testing knowledge base for PHP 8.5 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.
ab-testing
Use when designing experiments for subject lines, offers, cadences, or journeys.
ab-testing-statistician
Expert in statistical analysis for blind A/B and ABX audio testing. Validates randomization, calculates statistical significance, and ensures proper experimental design. Use when implementing A/B test features or analyzing test results.
ab-testing-analyzer
全面的AB测试分析工具,支持实验设计、统计检验、用户分群分析和可视化报告生成。用于分析产品改版、营销活动、功能优化等AB测试结果,提供统计显著性检验和深度洞察。
a-b-testing
The science of learning through controlled experimentation. A/B testing isn't about picking winners—it's about building a culture of validated learning and reducing the cost of being wrong. This skill covers experiment design, statistical rigor, feature flagging, analysis, and building experimentation into product development. The best experimenters know that every test, positive or negative, teaches something valuable. Use when "a/b test, experiment, hypothesis, statistical significance, sample size, feature flag, variant, control, treatment, p-value, conversion rate, test winner, split test, experimentation, testing, statistics, feature-flags, hypothesis, growth, optimization, learning, validation" mentioned.
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Build Your Testing Skill
Create your agent-tdd skill in one prompt, then learn to improve it throughout the chapter