Get the FREE Ultimate OpenClaw Setup Guide →

pwp-test

Scanned
npx machina-cli add skill shandar/pwp-plugin/pwp-test --openclaw
Files (1)
SKILL.md
4.7 KB

PWP Testing Protocol

You are now operating under the Project Workflow Protocol's testing discipline. Follow this structured approach for every testing task.

Context: $ARGUMENTS

Phase 1: Assess Testing Needs

Before writing any test, understand:

  1. What is being tested? — Business logic, API endpoint, UI component, integration?
  2. What layer of the test pyramid? — Unit (fast, many), Integration (medium, some), E2E (slow, few)
  3. What already exists? — Check for existing test files, test utils, and coverage reports
  4. What's the testing stack? — Jest, Vitest, Playwright, Cypress, React Testing Library, etc.

Phase 2: Apply the Test Pyramid

Distribute testing effort intentionally:

LayerWhat It TestsSpeedQuantity
UnitPure functions, utilities, isolated logicFast (ms)Many
IntegrationComponent interactions, API endpoints, DB queriesMedium (s)Some
E2EFull user journeys through real UISlow (min)Few

Always Test

  • Business logic and calculations
  • Data transformations and parsing
  • Edge cases: empty inputs, null values, boundary conditions
  • Error paths: what happens when things fail
  • API contracts: request/response shapes
  • Auth and permission logic

Test With Judgment

  • Component rendering (test behavior, not snapshot every div)
  • Form validation rules
  • State transitions
  • Navigation flows

Rarely Test

  • Third-party library internals (trust the library, mock the boundary)
  • Pure styling (visual regression tools handle this better)
  • One-line getters or trivial pass-through functions
  • Framework boilerplate

Phase 3: Write Tests

File Naming

Co-locate test files with source:

src/utils/formatCurrency.ts
src/utils/formatCurrency.test.ts      ← co-located
src/components/InvoiceTable.tsx
src/components/InvoiceTable.test.tsx   ← co-located
__tests__/integration/checkout.test.ts ← integration in dedicated folder

Test Case Naming

Pattern: it('should {expected behavior} when {condition}')

describe('formatCurrency')
  it('should format positive numbers with two decimals')
  it('should return "$0.00" when given zero')
  it('should handle negative numbers with a minus prefix')
  it('should throw when given NaN')

Test Data Rules

  • Use factories, not fixtures. Generate test data with overridable defaults.
  • No production data. Use realistic but synthetic data.
  • Isolate state. Each test sets up and tears down its own state.
  • Name clearly. validUser, expiredToken, emptyCart — not testData1.

Phase 4: When to Write Tests

ScenarioApproach
New business logicWrite tests alongside implementation
Bug fixWrite failing test first, then fix (TDD for bugs)
RefactoringEnsure tests exist BEFORE refactoring (safety net)
Exploratory/prototypeSkip tests, but flag as untested
Performance-critical pathAdd benchmark tests with baseline thresholds

Phase 5: Coverage Targets

ContextTargetRationale
Business logic / utils90%+Most testable and most critical
API routes / controllers80%+Integration tests cover important paths
UI components60%+Test behavior and interactions
Overall project70%+Meaningful floor that compounds confidence

Coverage is a compass, not a destination.

Philosophy (non-negotiable)

  • Test behavior, not implementation. Tests should survive refactors.
  • Tests are documentation. A well-named test suite tells the next dev what the code does.
  • Diminishing returns are real. 80% meaningful coverage beats 100% checkbox coverage.
  • Flaky tests are worse than no tests. A flaky test erodes trust in the entire suite. Fix or delete.

Verification Checklist

After writing tests, confirm:

  • New business logic has corresponding tests
  • Bug fixes include a regression test
  • Tests are named descriptively (behavior + condition)
  • Test data is synthetic, isolated, and clearly named
  • No test depends on another test's state
  • Flaky tests are fixed or removed
  • Coverage targets met for changed code
  • Test suite passes with exit code 0

Source

git clone https://github.com/shandar/pwp-plugin/blob/main/skills/pwp-test/SKILL.mdView on GitHub

Overview

pwp-test defines a disciplined approach to testing: understand what to test, apply the test pyramid, and implement clear naming and data factories. It emphasizes coverage targets and when to test what, so teams catch real bugs early. This guide helps you set up testing strategies, write testable code, and maintain meaningful test suites.

How This Skill Works

Follow Phase 1 through Phase 5 to implement tests: assess testing needs, distribute tests by the pyramid (unit, integration, E2E), and decide when to write tests. Enforce co-located test files, descriptive naming patterns, and factories for test data. Use the coverage targets as a compass to balance effort and risk.

When to Use It

  • User asks to write tests, add test coverage, or set up a testing strategy
  • Need to decide which testing layer to target (unit, integration, E2E)
  • Need to ensure test data quality using factories instead of fixtures
  • You're fixing a bug and want to apply TDD-style tests first
  • Setting up testing standards, naming, and coverage targets across the project

Quick Start

  1. Step 1: Assess testing needs and stack (Unit, Integration, E2E) for the feature
  2. Step 2: Write co-located tests with clear naming and build data via factories
  3. Step 3: Set coverage targets and iterate on tests as requirements evolve

Best Practices

  • Co-locate test files with source files (same folder as the implementation)
  • Use factories, not fixtures, with overridable defaults
  • Name tests clearly using patterns like it('should ...')
  • Distribute tests according to the pyramid: unit first, then integration, then E2E
  • Isolate state for each test and keep tests deterministic

Example Use Cases

  • Unit test a pure function in src/utils/formatCurrency.ts
  • Integration test for an API endpoint (e.g., /users) with realistic data
  • E2E test for a user journey (login, navigate, perform action)
  • Test data built with factories: validUser, expiredToken, emptyCart
  • Add regression tests before refactoring to serve as a safety net

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers