backend-testing

Write unit, integration, and API tests for backend services using Jest, Pytest, and Supertest.

2|Updated Mar 7, 2025
One-click install
npx skills add https://github.com/AbdelrhmanUZaki/KnowledgeNuggets --skill backend-testing-abdelrhmanuzaki
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: backend-testing
Source: https://github.com/AbdelrhmanUZaki/KnowledgeNuggets/tree/main/2-setup/shared/gemini/config/skills/backend-testing
Command: npx skills add https://github.com/AbdelrhmanUZaki/KnowledgeNuggets --skill backend-testing-abdelrhmanuzaki

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Backend code often ships without adequate test coverage, leading to regressions, broken API contracts, and authentication bugs discovered only in production. This Skill provides a structured workflow for writing unit tests, integration tests, and authentication tests with proper isolation, mocking, and coverage enforcement. ## Core Features & Use Cases - Unit Testing: Test pure functions and business logic using the AAA pattern with edge-case coverage, such as password validation rules. - API Integration Testing: Verify REST endpoints with Supertest or FastAPI TestClient, covering success cases, validation errors, duplicate handling, and database state changes. - Auth & Mocking: Test JWT-protected routes, role-based access control, and mock external services like email APIs to keep tests isolated and fast. - Use Case: When adding a new /auth/register endpoint to an Express app, generate a full Jest + Supertest suite covering 201 success, 409 duplicate email, 400 weak password, and 401 login failures, with 80% coverage thresholds enforced in jest.config.js. ## Quick Start Ask the AI to write Jest and Supertest tests for your Express authentication endpoints covering registration, login, and protected routes with at least 80 percent coverage.

Frequently Asked Questions about backend-testing

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

FAQPage Schema
How do I test REST API endpoints with Jest and Supertest?▼

Use Supertest to send HTTP requests against your Express app and assert on status codes, response bodies, and database state. Wrap each test suite in describe blocks, reset the database in beforeEach, and cover both success cases like 201 and failure cases like 400, 401, and 409.

How to write unit tests for backend business logic?▼

Follow the AAA pattern: Arrange inputs, Act by calling the function, and Assert on outputs. Test pure functions directly, mock external dependencies with jest.mock or unittest.mock, and cover edge cases such as boundary values and invalid inputs.

Jest vs Pytest for backend API testing?▼

Jest with Supertest suits Node.js frameworks like Express, while Pytest with FastAPI TestClient fits Python services. Both support fixtures or setup hooks, mocking, and coverage reporting, so choose based on your application's language and framework.

Can I run backend tests against a production database?▼

No, tests must never run against a production database. Use an in-memory database like SQLite or a separate test database, and reset state with migrations in beforeEach and afterEach hooks to keep tests isolated and repeatable.

Why does Jest not exit after tests finish?▼

Jest hangs when open handles like database connections or servers are not closed. Fix it by destroying connections and closing servers in an afterAll hook, for example calling db.destroy() and server.close() after the suite completes.

How do I test JWT-protected routes and role-based access?▼

Register or log in a test user to obtain a token, then send it in the Authorization header as a Bearer token. Assert 401 for missing tokens, 403 for invalid tokens or insufficient roles, and 200 for valid authorized requests.