testing-patterns

Guides unit, integration, and E2E test design with mocking strategies and a unified test runner script.

2|Updated May 30, 2026
One-click install
npx skills add https://github.com/virahitvin8/crafty-gis --skill testing-patterns-virahitvin8
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-patterns
Source: https://github.com/virahitvin8/crafty-gis/tree/main/GIT_STAR/.agent/skills/testing-patterns
Command: npx skills add https://github.com/virahitvin8/crafty-gis --skill testing-patterns-virahitvin8

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? Writing reliable tests is hard: developers struggle to choose between unit, integration, and E2E tests, decide what to mock, and structure test suites that stay fast and maintainable. This Skill provides proven testing principles plus a script that detects and runs your project's test framework automatically. ## Core Features & Use Cases - Testing Strategy Guidance: Covers the testing pyramid, AAA pattern, test type selection, and when to use unit vs integration vs E2E tests. - Mocking & Test Data Patterns: Explains stubs, spies, mocks, and fakes, plus factories, fixtures, and builders for test data. - Unified Test Runner: The included Python script auto-detects Node.js (Jest, Vitest, npm test) or Python (pytest) projects, runs tests with optional coverage, and reports pass/fail counts as JSON. - Use Case: You are adding tests to a Node.js API project. Use this Skill to decide which endpoints need integration tests, how to mock the database layer, then run the test_runner script to execute Jest with coverage and get a structured summary. ## Quick Start Ask the assistant to review my test suite using the testing-patterns skill and run the test runner script on my project with coverage enabled.

Frequently Asked Questions about testing-patterns

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

FAQPage Schema
How do I choose between unit, integration, and E2E tests?

Use unit tests for pure functions and business logic since they run fast, integration tests for API endpoints and database queries, and E2E tests sparingly for critical user flows. Follow the testing pyramid: many unit tests, some integration tests, few E2E tests.

How to run Jest or pytest tests with coverage from one script?

Run the included test_runner.py script with your project path and the --coverage flag. It auto-detects Jest, Vitest, npm test, or pytest, executes the right coverage command, and prints a JSON summary with pass and fail counts.

When should I mock dependencies in unit tests?

Mock external APIs, databases, network calls, time, and randomness to keep unit tests fast and isolated. Do not mock the code under test, pure functions, or simple in-memory dependencies.

What is the difference between a stub, spy, mock, and fake?

A stub returns fixed values, a spy records how it was called, a mock verifies expected interactions, and a fake is a simplified working implementation such as an in-memory database. Choose based on whether you need return values, call tracking, or behavior verification.

Why are my tests flaky and how do I fix them?

Flaky tests usually come from shared state, order dependencies, unmocked time or randomness, or missing cleanup. Make tests independent, reset state in beforeEach hooks, mock non-deterministic inputs, and fix root causes instead of ignoring failures.