test-writing-patterns

Guides developers on test structure, assertions, test doubles, and organization for TDD.

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/rubrical-works/idpf-praxis-skills --skill test-writing-patterns-rubrical-works
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: test-writing-patterns
Source: https://github.com/rubrical-works/idpf-praxis-skills/tree/main/Skills/test-writing-patterns
Command: npx skills add https://github.com/rubrical-works/idpf-praxis-skills --skill test-writing-patterns-rubrical-works

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing maintainable, well-structured tests is hard: developers struggle with choosing test structures, picking the right test double, writing meaningful assertions, and keeping tests isolated and organized. This Skill provides experienced developers with proven patterns for effective test-driven development. ## Core Features & Use Cases - Test Structure Patterns: AAA (Arrange-Act-Assert), Given-When-Then, and Four-Phase patterns with templates and common mistakes. - Test Doubles Guidance: Clear selection criteria for stubs, mocks, fakes, and spies, with a decision matrix and anti-patterns. - Assertion & Organization Strategies: Single-concept assertions, naming conventions, parameterized tests, and test suite organization by type or feature. - Use Case: When writing a unit test for a service that calls an external API, use this Skill to decide between a stub and a mock, structure the test with AAA, and write specific assertions with helpful failure messages. ## Quick Start Ask the AI to help you structure a test for a specific function using the AAA pattern and recommend the right test double for its dependencies.

Frequently Asked Questions about test-writing-patterns

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

FAQPage Schema
How do I structure a unit test using the AAA pattern?▼

Arrange-Act-Assert divides a test into three sections: set up test data and dependencies (Arrange), execute the behavior being tested (Act), then verify the expected outcome (Assert). Keep the Act step to a single action and make assertions specific.

What is the difference between a mock, stub, fake, and spy?▼

A stub returns predetermined responses, a mock verifies interactions and call parameters, a fake is a simplified working implementation like an in-memory database, and a spy wraps a real object to record calls while delegating to real behavior.

When should I use parameterized tests in pytest or Jest?▼

Use parameterized tests when the same test logic applies to multiple inputs, such as edge cases, boundary values, or validation rules. pytest uses @pytest.mark.parametrize and Jest uses test.each to run each case independently.

Why do my tests break when I refactor code?▼

Brittle tests usually assert on implementation details instead of observable behavior. Fix this by testing outcomes and public interfaces rather than internal state, and avoid over-mocking dependencies.

Does 100% code coverage mean my tests are good?▼

No. Coverage only shows which code is executed by tests, not whether behaviors, edge cases, or error paths are verified. Focus on meaningful tests for critical paths rather than chasing coverage percentages.

How do I fix tests that depend on execution order?▼

Order-dependent tests violate isolation. Give each test its own setup and teardown, use fresh fixtures per test, avoid shared mutable state, and use transactions or in-memory databases that reset between tests.