Testing Patterns

This skill should be used when the user asks to "write tests", "test strategy", "coverage", "unit test", "integration test", or needs testing guidance. Provides testing methodology and patterns.

$ インストール

git clone https://github.com/takeokunn/nixos-configuration /tmp/nixos-configuration && cp -r /tmp/nixos-configuration/home-manager/programs/claude-code/skills/testing-patterns ~/.claude/skills/nixos-configuration

// tip: Run this command in your terminal to install the skill


name: Testing Patterns description: This skill should be used when the user asks to "write tests", "test strategy", "coverage", "unit test", "integration test", or needs testing guidance. Provides testing methodology and patterns.

<test_phase>Act: Execute the code under test</test_phase>

total = cart.calculate_total

<test_phase>Assert: Verify expected outcomes</test_phase>

assert_equal 0, total Separates setup, execution, and verification into distinct phases

<bdd_step>When: Action or trigger</bdd_step>

when_the_user_calculates_total

<bdd_step>Then: Expected outcome</bdd_step>

then_the_total_should_be_zero Emphasizes business behavior over technical implementation

def save(key, value) @data[key] = value end

def find(key) @data[key] end end <use_case>In-memory database, fake file system</use_case>

<best_practices> Test happy path first Start with the normal, expected flow before edge cases test_userLogin_withValidCredentials_succeeds test_userLogin_withInvalidPassword_fails test_userLogin_withLockedAccount_fails

def teardown @database.clear end

Bad: Unclear purpose

test_user_reg_1

Avoid: Multiple unrelated assertions

test_userCreation user = create_user assert_equal "member", user.role assert_not_nil user.email assert_true user.active end

<bad_example>Bad</bad_example>

test_userValidation_withValidAge_succeeds user = User.new(age: 25) assert user.valid? end

<related_agents> Primary agent for implementing tests alongside feature code Use for reviewing test quality and coverage Delegate to when tests reveal unexpected failures </related_agents>

<related_skills> Use to define test requirements and acceptance criteria Use to implement tests as part of feature development workflow Use when debugging test failures or flaky tests </related_skills>

<anti_patterns> Testing implementation details instead of behavior Focus on testing observable behavior and outcomes, not internal implementation details. Test what the code does, not how it does it.

<error_escalation> Minor coverage gap in non-critical path Note in report, proceed Test flakiness detected Document issue, use AskUserQuestion for clarification Critical path lacks test coverage STOP, present options to user Tests reveal security vulnerability BLOCK operation, require explicit user acknowledgment </error_escalation>

Repository

takeokunn
takeokunn
Author
takeokunn/nixos-configuration/home-manager/programs/claude-code/skills/testing-patterns
52
Stars
0
Forks
Updated6d ago
Added1w ago