prioritize-unit-testing-and-refactor-for-testability

Installation
SKILL.md

Summary

Focus your testing efforts on the base of the Test Pyramid: Unit Tests. If code is hard to unit test, do not rely on slow integration tests; instead, refactor the code by extracting logic into smaller, testable functions (refer to the Refactoring Guidelines, such as "Keep functions short").

Rationale

  • Speed: Unit tests run in milliseconds, providing immediate feedback. Integration tests are slow and brittle.
  • Design Feedback: "Hard to test" usually means "Bad design" (tight coupling, hidden dependencies).
  • Coverage: It is impossible to cover all edge cases (permutations) with expensive E2E/Integration tests. Only Unit tests can cheaply cover all branches.

Guidance

  1. Refactor to Test:
    • If a function is too complex to test easily, extract the logic into helper functions.
    • Follow the Refactoring Guidelines (e.g. "Keep Functions Short" / Top-Down Decomposition) when extracting. Do not split arbitrarily.
  2. Encapsulation with Internals:
    • Move extracted helper functions to an internal/ package (Go) or directory (TS/JS) if they shouldn't be part of the public API.
    • Test these internal units directly to verify complex logic in isolation.
  3. Pyramid Shape:
    • 70% Unit Tests: Fast, isolated, covers all edge cases.
    • 20% Integration Tests: Covers valid paths and major error cases across boundaries.
    • 10% E2E Tests: Covers critical user flows ("Happy Path").
Installs
1
First Seen
Apr 5, 2026
prioritize-unit-testing-and-refactor-for-testability — mew-ton/coding-guidelines