# Testing Best Practices

> Guidelines for implementing effective and maintainable tests.

- Skill: `matrixfounder/testing-best-practices` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add matrixfounder/testing-best-practices`
- Raw SKILL.md: https://api.skillmd.com/api/skills/matrixfounder/testing-best-practices/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: MatrixFounder (https://skillmd.com/u/matrixfounder)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/matrixfounder/testing-best-practices

---

# Testing Best Practices

## 1. Hierarchy & Strategy
- **E2E (End-to-End):** Mandatory for every task.
  - *Stub Stage:* Assert hardcoded values (verify structure).
  - *Impl Stage:* Assert real logic (verify behavior).
- **Unit:** Cover edge cases, error handling, and specific algorithms.
- **Regression:** ALWAYS run the full test suite before submitting.

## 2. Critical Rules
- **NO LLM MOCKING in Tests:** Do not mock OpenAI/Anthropic calls in standard tests. Use recorded responses (VCR.py) or separate integration environments.
- **Realism:** Minimize mocks. Test real component capability where possible.
- **Isolation:** Tests must be independent. Database state should be reset between tests.
- **Environment:** Use the project's virtual environment (e.g., `/opt/projects/.../venv`).

## 3. Naming & Structure
- **Clear Names:** `test_shoud_return_error_when_invalid_input`.
- **Organization:** Mirror source structure (`src/auth` -> `tests/auth`).
- **Docstrings:** specificy WHAT is being tested.
- **Reference Examples:**
  - Python: `examples/pytest_structure.py`
  - JavaScript: `examples/jest_structure.js`

## 4. Resources
- **Templates:** Use `assets/templates/test_boilerplate.py` to start new test files quickly.

