Skip to content
Back to skills

Testing Patterns

ASecurity

Unit and integration test patterns - pyramid, AAA, mocking, test data, suite runs; use when writing or running tests.

  • 6 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 5, 2026
developmentpythongotestinggitapidatabasedocumentation

Works with

  • api

Security analysis

A100/100

Scanned December 5, 2026

npx -y skills add Reprograme/redevkit --skill testing-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Testing Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Testing Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/reprograme-testing-patterns/badge)](https://www.skillsdirectory.com/skills/reprograme-testing-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: testing-patterns
description: Unit and integration test patterns - pyramid, AAA, mocking, test data, suite runs; use when writing or running tests.
---

# Testing Patterns

> Principles for reliable test suites. Tests are written first by default
> (`{{SKILL:tdd-workflow}}`); end-to-end browser tests are in `{{SKILL:webapp-testing}}`.

## 1. Running the Suite and Reporting

`{{CMD:redevkit-test}}` maps the acceptance scenarios of `specs/NNN-name/spec.md` to tests,
writes the missing ones, runs the active spec's tests (the whole suite inside
`{{CMD:redevkit-verify}}`) and **appends** a dated run to
`specs/NNN-name/test-report.md` (template `reports/test-report.md`: use
`.redevkit/templates/overrides/reports/test-report.md` if it exists, otherwise
`.redevkit/templates/reports/test-report.md`). Write the report in the project language
(`{{LANG}}`).

How to run:

1. The tests run as `{{CMD:redevkit-test}}` step 3 says: Python found →
   `.redevkit/audits/test_runner.py` per `.redevkit/audits/README.md` (exit `3` → the
   `tech.md` test command); no Python → the `tech.md` test command. While implementing, run
   only the tests you touched (light verification, `{{SKILL:lint-and-validate}}`).
2. Each run in the report records: the commands, the observed results (passed, failed,
   skipped), which acceptance scenarios are covered, the commit (`git rev-parse HEAD`) and
   whether the working tree was clean (`git status --porcelain`).

Never report a suite as passing without a run you observed. A red run hands off to
`{{CMD:redevkit-debug}}`.

## 2. Testing Pyramid

```text
        /\          E2E (few)
       /  \         critical flows
      /----\
     /      \       Integration (some)
    /--------\      API, DB queries
   /          \
  /------------\    Unit (many)
                    functions, classes
```

## 3. AAA Pattern

| Step | Purpose |
| --- | --- |
| **Arrange** | Set up test data |
| **Act** | Execute the code under test |
| **Assert** | Verify the outcome |

## 4. Test Type Selection

| Type | Best for | Speed |
| --- | --- | --- |
| **Unit** | Pure functions, logic | Fast (< 100 ms) |
| **Integration** | API, DB, services | Medium |
| **E2E** | Critical user flows | Slow |

## 5. Unit Test Principles

| Principle | Meaning |
| --- | --- |
| Fast | < 100 ms each |
| Isolated | No external dependencies |
| Repeatable | Same result always |
| Self-checking | No manual verification |
| Timely | Written before or with the code |

| Test | Don't test |
| --- | --- |
| Business logic | Framework code |
| Edge cases | Third-party libraries |
| Error handling | Trivial getters |

## 6. Integration Test Principles

| Area | Focus |
| --- | --- |
| API endpoints | Request/response, status codes, schema |
| Database | Queries, transactions, migrations |
| External services | Contracts |

| Phase | Action |
| --- | --- |
| Before all | Connect resources |
| Before each | Reset state |
| After each | Clean up |
| After all | Disconnect |

## 7. Mocking Principles

| Mock | Don't mock |
| --- | --- |
| External APIs | The code under test |
| Database (in unit tests) | Simple dependencies |
| Time / randomness | Pure functions |
| Network | In-memory stores |

| Type | Use |
| --- | --- |
| Stub | Return fixed values |
| Spy | Track calls |
| Mock | Set expectations |
| Fake | Simplified working implementation |

## 8. Test Organization

| Naming pattern | Example |
| --- | --- |
| Should behavior | "should return error when..." |
| When condition | "when user not found..." |
| Given-when-then | "given X, when Y, then Z" |

| Level | Use |
| --- | --- |
| `describe` | Group related tests |
| `it` / `test` | Individual case |
| `beforeEach` | Common setup |

Name tests after the acceptance scenario they cover (for example `US1 scenario 2`) so the
report can map scenarios to tests.

## 9. Test Data

| Approach | Use |
| --- | --- |
| Factories | Generate test data |
| Fixtures | Predefined datasets |
| Builders | Fluent object creation |

- Use realistic data; randomize only non-essential values (faker) with a fixed seed.
- Share common fixtures; keep data minimal.
- Never use production secrets or personal data.

## 10. Best Practices

| Practice | Why |
| --- | --- |
| One behavior per test | Clear failure reason |
| Independent tests | No order dependency |
| Fast tests | Run them often |
| Descriptive names | Self-documenting |
| Clean up | No side effects between tests |

## 11. Anti-Patterns

| ❌ Don't | ✅ Do |
| --- | --- |
| Test implementation | Test behavior |
| Duplicate test code | Use factories |
| Complex test setup | Simplify or split |
| Ignore flaky tests | Fix the root cause |
| Skip cleanup | Reset state |
| Weaken an assertion to go green | Fix the code or ask |

> **Remember:** Tests are documentation. If someone can't understand what the code does from
> the tests, rewrite them.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.