testing-patterns

Apply testing patterns to introduce seams and characterization tests in JavaScript/TypeScript projects.

38|3|Updated Mar 22, 2024
One-click install
npx skills add https://github.com/anthonyshew/dotfiles --skill testing-patterns-anthonyshew
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-patterns
Source: https://github.com/anthonyshew/dotfiles/tree/main/opencode/.config/opencode/skill/testing-patterns
Command: npx skills add https://github.com/anthonyshew/dotfiles --skill testing-patterns-anthonyshew

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Patterns for testing code effectively address the challenge of changing code safely by introducing seams, characterization tests, and dependency-breaking strategies.

Core Features & Use Cases

  • Seam-based design to alter behavior without editing source files.
  • Characterization tests to document actual behavior for safe refactoring.
  • Guidance on breaking dependencies, test doubles, and safe testing workflows.

Quick Start

Start by identifying a legacy module and outline a plan to introduce seams, write characterization tests, and replace hard dependencies with test doubles to enable safe changes.

Frequently Asked Questions about testing-patterns

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

FAQPage Schema
How do I write characterization tests to safely refactor legacy code?

Characterization tests document the actual behavior of existing code before refactoring. You write them by capturing current outputs as assertions, creating a safety net to verify behavior remains unchanged after modifying the source.

What are seams in unit testing and how do they help break dependencies?

Seams are specific locations in code where you can alter behavior without editing the source file. They enable dependency injection and test doubles, allowing you to isolate modules and break hard dependencies for safer unit testing.

Can I apply these testing patterns to both OO and functional codebases?

Yes, these testing patterns apply across both object-oriented and functional codebases. The strategies for adding tests, breaking dependencies, and characterizing existing behavior are designed to be universally applicable.

Do these dependency breaking strategies work with JavaScript and TypeScript projects?

Yes, the dependency breaking strategies include concrete examples tailored for JavaScript and TypeScript projects. You can immediately apply patterns for seams, characterization tests, and test doubles in your JS/TS codebase.

What's the best way to start adding tests to an existing module with hard dependencies?

Start by identifying a legacy module, then outline a plan to introduce seams. Write characterization tests to document current behavior, and replace hard dependencies with test doubles to enable safe changes.

When should I use characterization tests instead of standard unit tests?

Use characterization tests when you need to safely evolve legacy code with unknown or undocumented behavior. Unlike standard unit tests that define expected behavior, characterization tests capture actual current behavior to prevent regressions during refactoring.