backend-testing

Designs and implements backend unit, API, and integration tests with coverage contracts.

Updated Jun 28, 2026
One-click install
npx skills add https://github.com/jason23452/my-skill --skill backend-testing-jason23452
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: backend-testing
Source: https://github.com/jason23452/my-skill/tree/main/backend/backend-testing
Command: npx skills add https://github.com/jason23452/my-skill --skill backend-testing-jason23452

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Backend services often ship without adequate test coverage, or tests are flaky, hit real databases, and lack clear verification commands. This Skill provides a structured contract for designing, adding, and repairing backend tests so coverage is deterministic, isolated, and CI-ready. ## Core Features & Use Cases - Test Strategy & Layering: Chooses the smallest effective test layer (service/unit, API/route, integration) based on repo evidence, keeping the existing test runner and assertion style. - Fixture & Isolation Rules: Defines database isolation via transaction rollback, schema reset, or testcontainers, plus mocking of outbound HTTP, email, payment, and queue calls with tools like respx and pytest-mock. - Testing Contract Output: Generates an exact Backend Testing Contract section with test runner, paths, fixtures, coverage command, and CI command, blocking with BACKEND_TEST_CONTRACT_MISSING when key details cannot be determined. - Use Case: When adding a new FastAPI endpoint, use this Skill to create TestClient or async HTTPX tests that assert status codes, response shapes, and validation failures, then run pytest with coverage before finishing. ## Quick Start Use the backend-testing skill to add pytest API and unit tests with coverage for this FastAPI service.

Frequently Asked Questions about backend-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add pytest tests to a FastAPI project?▼

Add pytest, httpx, pytest-cov, anyio, pytest-mock, and respx as dev dependencies, then create a tests directory with conftest.py, api, unit, and integration subfolders. Use TestClient for synchronous endpoint tests and httpx.AsyncClient with ASGITransport plus pytest.mark.anyio for async code.

What is the best way to test FastAPI endpoints?▼

Use FastAPI's TestClient for simple synchronous endpoint tests, calling the ASGI app in-process without starting Uvicorn. For tests that must await async database or service calls, use httpx.AsyncClient with ASGITransport and the anyio marker.

How do I mock external HTTP calls in pytest?▼

Use respx to mock outbound HTTPX requests by defining expected routes and mock responses, then assert the route was called. For non-HTTP dependencies like gateways or services, use pytest-mock to patch at the application boundary.

How do I isolate database state between tests?▼

Use transaction rollback per test, a fresh schema with table cleanup, or testcontainers for PostgreSQL integration tests when Docker is available. Override the app's session dependency with a test engine, and never point tests at production or staging databases.

Should I use TestClient or AsyncClient for FastAPI tests?▼

Use TestClient for simple synchronous endpoint tests where no awaiting is needed. Choose httpx.AsyncClient with ASGITransport when tests must await async database or service code, and add asgi-lifespan only if startup and shutdown events must run.