essential-test-design
A focused testing skill for writing robust, contract-based tests.
Install
mkdir -p .claude/skills/essential-test-design && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/2727" && unzip -o skill.zip -d .claude/skills/essential-test-design && rm skill.zipInstalls to .claude/skills/essential-test-design
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Write tests that verify observable behavior (contract), not implementation details. Auto-invoked when writing or reviewing tests.Key capabilities
- →Design contract-based unit tests
- →Verify observable behavior over implementation
- →Implement boundary assertions for async logic
- →Review test suites for coupling
- →Mock external boundaries
How it works
The skill guides developers to test what the caller experiences, using boundary assertions and mocking external boundaries to ensure tests survive refactoring.
Inputs & outputs
When to use essential-test-design
- →Write contract-based unit tests
- →Review test suites for implementation coupling
- →Design behavior-driven test cases
About this skill
Problem
Tests that are tightly coupled to implementation details cause two failures:
- False positives — Tests pass even when behavior is broken (e.g., delay shortened but test still passes because it only checks
setTimeoutwas called) - False negatives — Tests fail even when behavior is correct (e.g., implementation switches from
setTimeoutto adelay()utility, spy breaks)
Both undermine the purpose of testing: detecting regressions in behavior.
Principle: Test the Contract, Not the Mechanism
A test is "essential" when it:
- Fails if the behavior degrades (catches real bugs)
- Passes if the behavior is preserved (survives refactoring)
- Does not depend on how the behavior is implemented (implementation-agnostic)
Ask: "What does the caller of this function experience?" — test that.
Anti-Patterns and Corrections
Anti-Pattern 1: Implementation Spy
// BAD: Tests implementation, not behavior
// Breaks if implementation changes from setTimeout to any other delay mechanism
const spy = vi.spyOn(global, 'setTimeout');
await exponentialBackoff(1);
expect(spy).toHaveBeenCalledWith(expect.any(Function), 1000);
Anti-Pattern 2: Arrange That Serves the Assert
// BAD: The "arrange" is set up only to make the "assert" trivially pass
// This is a self-fulfilling prophecy, not a meaningful test
vi.advanceTimersByTime(1000);
await promise;
// No assertion — "it didn't throw" is not a valuable test
Correct: Behavior Boundary Test
// GOOD: Tests the observable contract
// "Does not resolve before the expected delay, resolves at the expected delay"
let resolved = false;
mailService.exponentialBackoff(1).then(() => { resolved = true });
await vi.advanceTimersByTimeAsync(999);
expect(resolved).toBe(false); // Catches: delay too short
await vi.advanceTimersByTimeAsync(1);
expect(resolved).toBe(true); // Catches: delay too long or hangs
Decision Framework
When writing a test, ask these questions in order:
- What is the contract? — What does the caller expect to experience?
- e.g., "Wait for N ms before resolving"
- What breakage should this test catch? — Define the regression scenario
- e.g., "Someone changes the delay from 1000ms to 500ms"
- Would this test still pass if I refactored the internals? — If no, you're testing implementation
- e.g., Switching from
setTimeouttoBun.sleep()shouldn't break the test
- e.g., Switching from
- Would this test fail if the behavior degraded? — If no, the test has no value
- e.g., If delay is halved,
expect(resolved).toBe(false)at 999ms would catch it
- e.g., If delay is halved,
Common Scenarios
Async Delay / Throttle / Debounce
Use fake timers + boundary assertions (as shown above).
Data Transformation
Assert on output shape/values, not on which internal helper was called.
// BAD
const spy = vi.spyOn(utils, 'formatDate');
transform(input);
expect(spy).toHaveBeenCalled();
// GOOD
const result = transform(input);
expect(result.date).toBe('2026-01-01');
Side Effects (API calls, DB writes)
Mocking the boundary (API/DB) is acceptable — that IS the observable behavior.
// OK: The contract IS "sends an email via mailer"
expect(mockMailer.sendMail).toHaveBeenCalledWith(
expect.objectContaining({ to: '[email protected]' })
);
Retry Logic
Test the number of attempts and the final outcome, not the internal flow.
// GOOD: Contract = "retries N times, then fails with specific error"
mockMailer.sendMail.mockRejectedValue(new Error('fail'));
await expect(sendWithRetry(config, 3)).rejects.toThrow('failed after 3 attempts');
expect(mockMailer.sendMail).toHaveBeenCalledTimes(3);
Guard / Drift Specs ("X must never happen" tests)
A spec that asserts a codebase invariant (e.g. "no static import chain from a boot entrypoint reaches a heavy package") can rot silently: if its walk starts from a wrong or renamed root it traces nothing and passes vacuously — green forever, guarding nothing.
- Prove it can fail before committing it (mutation check): introduce the violation deliberately (re-add the banned import / legacy code path), confirm the spec goes RED with a message pointing at the cause, then revert. Include the red output as evidence in the PR.
- Guard the guard: assert that every walked entrypoint/fixture still exists, so a rename fails the spec instead of emptying the walk.
Real case: the no-eager-*-imports.spec.ts drift specs in apps/app each
shipped with mutation evidence; boot-rooted walks caught two real leak paths
(an admin route, a group-sync service) that module-rooted walks could not see.
When to Apply
- Writing new test cases for any function or method
- Reviewing existing tests for flakiness or brittleness
- Refactoring tests after fixing flaky CI failures
- Code review of test pull requests
When not to use it
- →Testing internal private methods
- →Tests that depend on specific implementation details
Prerequisites
Limitations
- →Requires clear definition of the contract
- →Tests must be implementation-agnostic
How it compares
It focuses on catching regressions in behavior rather than verifying internal function calls or implementation steps.
Compared to similar skills
essential-test-design side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| essential-test-design (this skill) | 2 | 2mo | No flags | Intermediate |
| webapp-testing | 353 | 3mo | Review | Intermediate |
| ui-ux-expert-skill | 91 | 9mo | Review | Advanced |
| skill-creator | 128 | 3mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by growilabs
View all by growilabs →You might also like
webapp-testing
anthropics
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
ui-ux-expert-skill
fercracix33
Technical workflow for implementing accessible React user interfaces with shadcn/ui, Tailwind CSS, and TanStack Query. Includes 6-phase process with mandatory Style Guide compliance, Context7 best practices consultation, Chrome DevTools validation, and WCAG 2.1 AA accessibility standards. Use after Test Agent, Implementer, and Supabase agents complete their work.
skill-creator
anthropics
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
python-testing-patterns
wshobson
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.
dependency-upgrade
wshobson
Manage major dependency version upgrades with compatibility analysis, staged rollout, and comprehensive testing. Use when upgrading framework versions, updating major dependencies, or managing breaking changes in libraries.
playwright-mcp
sfc-gh-dflippo
Browser testing, web scraping, and UI validation using Playwright MCP. Use this skill when you need to test Streamlit apps, validate web interfaces, test responsive design, check accessibility, or automate browser interactions through MCP tools.