testing-patterns

neokn's avatarfrom neokn

Write effective tests with proper structure and coverage. Use when writing unit tests, integration tests, or improving test quality.

⭐0stars🔀0forks📁View on GitHub🕐Updated Dec 15, 2025

When & Why to Use This Skill

The Testing Patterns skill empowers developers to build robust, maintainable software by implementing industry-standard testing methodologies. It provides structured guidance on the AAA (Arrange-Act-Assert) pattern, consistent naming conventions, and strategic mocking, ensuring high-quality code coverage across unit and integration tests while eliminating flaky or redundant test cases.

Use Cases

  • Standardizing Test Structure: Utilizing the AAA (Arrange-Act-Assert) pattern to create readable and organized unit tests for complex business logic.
  • Improving Test Maintainability: Applying descriptive naming conventions (e.g., test_unit_scenario_result) to ensure test suites serve as clear documentation for future developers.
  • Optimizing Integration Testing: Designing effective tests for API endpoints, database operations, and external service interactions to verify system-wide reliability.
  • Strategic Mocking: Implementing fast and deterministic tests by correctly mocking external APIs, databases, and time-dependent functions while avoiding brittle implementation-detail testing.
  • Quality Audit and Coverage: Evaluating existing test suites against a quality checklist to identify gaps in critical business logic and reduce technical debt from low-value tests.
nametesting-patterns
descriptionWrite effective tests with proper structure and coverage. Use when writing unit tests, integration tests, or improving test quality.
allowed-toolsRead, Write, Edit, Grep, Glob, Bash

Testing Patterns Skill

Help write clear, maintainable, effective tests.

Test Structure (AAA Pattern)

// Arrange - Set up test data and conditions
// Act - Execute the code under test
// Assert - Verify the expected outcome

Naming Convention

test_[unit]_[scenario]_[expected result]

Examples:
- test_calculateTotal_withEmptyCart_returnsZero
- test_login_withInvalidPassword_throwsAuthError
- test_fetchUser_whenNotFound_returns404

What to Test

Unit Tests

  • Pure functions and calculations
  • Business logic
  • Edge cases and boundaries
  • Error conditions

Integration Tests

  • API endpoints
  • Database operations
  • External service interactions
  • Authentication flows

Do NOT Test

  • Framework/library internals
  • Private methods directly
  • Trivial getters/setters
  • Third-party code

Test Quality Checklist

  • Tests one thing only
  • Clear test name describes behavior
  • Independent (no test order dependency)
  • Fast (mock external dependencies)
  • Deterministic (no flaky tests)
  • Readable (future you is the audience)

Mocking Guidelines

Mock:

  • External APIs
  • Database (for unit tests)
  • Time/dates
  • Random values
  • File system (when appropriate)

Don't mock:

  • The thing you're testing
  • Simple value objects
  • Everything (leads to brittle tests)

Coverage Strategy

Focus on:

  • Critical business logic: 90%+
  • Happy paths: 100%
  • Error paths: 80%+
  • Edge cases: Case by case

Avoid:

  • Chasing 100% blindly
  • Testing implementation details
  • Duplicate coverage