testing-patterns

Identify and apply testing patterns for safe refactoring in TypeScript codebases.

Updated Aug 30, 2024
One-click install
npx skills add https://github.com/minhtri2710/dotfiles --skill testing-patterns-minhtri2710
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-patterns
Source: https://github.com/minhtri2710/dotfiles/tree/main/dot_config/opencode/skill/testing-patterns
Command: npx skills add https://github.com/minhtri2710/dotfiles --skill testing-patterns-minhtri2710

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Patterns for testing code effectively, including seams, characterization tests, and safe refactoring techniques drawn from foundational testing literature.

Core Features & Use Cases

  • Seams & Characterization Tests: Document actual behavior to guide refactoring.
  • Breaking Dependencies: Techniques to safely isolate and test changes.
  • Test Doubles & DI: Use test doubles and dependency injection patterns.

Quick Start

Patterns and examples start here; consult the guides for concrete implementations.

Frequently Asked Questions about testing-patterns

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

FAQPage Schema
How do I make legacy code testable when it has tight dependencies?

Seams and dependency injection break tight coupling. Seams let you intercept behavior at specific points—through method parameters, extracted interfaces, or wrap method patterns—without modifying production code, enabling you to inject test doubles and isolate units for testing.

What are characterization tests and when should I use them?

Characterization tests document actual system behavior before refactoring. Write them to capture current output, then use them as a safety net while refactoring. They're essential when you lack a test suite and need confidence that changes don't alter external behavior.

How do I safely refactor code without breaking existing functionality?

Apply safe refactoring techniques: identify pinch points and interception points in your codebase, use sprout methods to extract logic incrementally, and rely on characterization tests as your safety net. These patterns guide structural changes while maintaining behavior across languages like TypeScript.

What's the difference between test doubles, and which should I use?

Test doubles (stubs, mocks, fakes) replace real dependencies during testing. Stubs return fixed values, mocks verify calls were made, fakes provide working implementations. Choose based on what you need to isolate: use stubs for read-heavy dependencies, mocks for behavior verification, fakes for stateful interactions.

Can I apply these testing patterns across different programming languages?

Yes. Seams, test doubles, dependency injection, and safe refactoring patterns are language-agnostic principles. The Skill covers applications in TypeScript and other languages, adapting technique names and syntax while preserving the core strategy for improving testability and enabling confident refactoring.

How do I identify where to break dependencies in a large codebase?

Locate pinch points—narrow sections where many dependencies flow through—and interception points where you can inject test doubles. Use wrap method patterns to intercept calls incrementally. Sprout methods extract testable logic without rewriting entire modules, prioritizing high-impact areas first.