---
name: unit-test-the-logic
description: "Applies “Unit-test the logic, not the framework” as a repeatable product-quality gate. Use during quality work when pure business rules tested at the edges — where the money bugs live."
---

# Unit-test the logic, not the framework

Apply this skill during **Quality** work. It supports Any stack.

Pure business rules tested at the edges — where the money bugs live.

## Instructions

Unit-test the pure core where the expensive bugs live: business rules, calculations, and state transitions. For each rule cover the happy path, every boundary (zero, negative, empty, maximum, duplicate), and malformed input. Money, dates, and timezones get edge-case tests by default: DST transitions, leap days, rounding direction, currency mismatch. Name tests as behavior specs — 'rejects a coupon after expiry' — so failures read as broken requirements. Mock only true externals (network, clock, randomness); if you must mock the thing you're testing, the design is wrong — fix the design. Periodically run a manual mutation check: break the logic deliberately and confirm a test catches it. A suite that can't catch a planted bug is decoration.

## Detect the problem

- Tests that restate the implementation
- High coverage, zero edge cases
- Mocking the function under test

## Hold the gate

Do not declare this phase complete until every item passes:

- [ ] Every pure business rule has unit tests: happy path, boundaries, malformed input
- [ ] Money/date/timezone logic tested at the edges: DST, leap days, rounding, zero, negative
- [ ] Test names state behavior ('rejects expired coupon'), not methods ('test1')
- [ ] Only true externals are mocked — never the logic under test
- [ ] Occasionally break the code on purpose and confirm a test fails (mutation check)

## Verify the result

Plant a deliberate bug in a core rule — a test must catch it, or the suite is decoration.
