testing-unit
Installation
SKILL.md
Unit Testing Patterns
Focused patterns for writing isolated, fast, maintainable unit tests. Covers test structure (AAA), parametrization, fixture management, HTTP mocking (MSW/VCR), and test data generation with factories.
Each category has individual rule files in rules/ loaded on-demand, plus reference material, checklists, and scaffolding scripts.
Core Principles (ALWAYS apply)
- AAA structure: Every test MUST follow Arrange-Act-Assert. Use
// Arrange,// Act,// Assertcomments for clarity. - Parametrize, don't duplicate: Use
test.each(TypeScript) or@pytest.mark.parametrize(Python) when testing multiple inputs. Never copy-paste the same test body with different values. - Fixture scoping matters: Use
scope="function"(default) for mutable data. Usescope="module"orscope="session"ONLY for expensive read-only resources (DB engines, ML models). Mutable data with shared scope causes flaky tests. - Speed target: Each unit test should run under 100ms. If it's slower, you're likely hitting I/O — mock it.
- Mock at the network level: Use MSW (TypeScript) or VCR.py (Python) to intercept HTTP at the network layer. Never mock
fetch/axios/requestsdirectly.