📚 Add testing principles to serena doc

This commit is contained in:
Andrey Antukh 2026-07-09 19:40:01 +02:00
parent 23a9b4bdd9
commit ad4dae5f28
4 changed files with 50 additions and 0 deletions

View File

@ -106,3 +106,4 @@ IMPORTANT: all CLI commands must be executed from the `backend/` subdirectory.
* **Coverage:** If code is added or modified in `src/`, corresponding tests in `test/backend_tests/` must be added or updated.
* **Isolated run:** `clojure -M:dev:test --focus backend-tests.my-ns-test` for a specific test namespace.
* **Regression run:** `clojure -M:dev:test` to ensure no regressions in related functional areas.
* **Principles:** Cross-cutting testing principles, anti-patterns, and verification checklist: `mem:common/testing-principles`.

View File

@ -49,6 +49,7 @@ Components, variants, and debugging:
Text and tests:
- Shared text data conversion, DraftJS compatibility, modern text content, and derived position data: `mem:common/text-subtleties`.
- Common test commands, helper conventions, production-path test mutations, and runtime coverage choices: `mem:common/testing`.
- Cross-cutting testing principles, anti-patterns, and verification checklist: `mem:common/testing-principles`.
## Areas without focused memories

View File

@ -0,0 +1,47 @@
# Testing Principles (Cross-Cutting)
Shared testing principles for all modules (backend, frontend, common, render-wasm, plugins). Module-specific commands and helpers are in each module's own testing memory.
## Core Principles
- **Test State, Not Interactions** — assert on outcomes, not method calls; survives refactoring
- **DAMP over DRY** — tests are specifications; duplication OK if each test is self-contained and readable
- **Prefer Real Implementations** — hierarchy: Real > Fake > Stub > Mock; mock only at boundaries (network, filesystem, email)
- **Arrange-Act-Assert** — every test: setup / action / verify
- **One Assertion Per Concept** — each test verifies one behavior; split compound assertions
- **Descriptive Test Names** — names read like specifications
## Anti-Patterns
- Testing implementation details → breaks on refactor
- Flaky tests (timing, order-dependent) → erode trust
- Mocking everything → tests pass, production breaks
- No test isolation → pass individually, fail together
- Testing framework code → waste of time
- Snapshot abuse → nobody reviews, break on any change
## Verification Checklist
After completing any implementation:
- Every new behavior has a corresponding test
- All tests pass for touched modules
- Bug fixes include a reproduction test that failed before the fix
- Test names describe the behavior being verified
- No tests were skipped or disabled
## Red Flags
- Writing code without corresponding tests
- Tests that pass on the first run (may not be testing what you think)
- Bug fixes without reproduction tests
- Tests that test framework behavior instead of app behavior
- Skipping tests to make the suite pass
## Rationalizations
- "I'll write tests after" → you won't; they'll test implementation not behavior
- "Too simple to test" → simple gets complicated; test documents expected behavior
- "Tests slow me down" → they speed up every future change
- "I tested manually" → manual testing doesn't persist
- "Code is self-explanatory" → tests ARE the specification
- "Just a prototype" → prototypes become production; test debt accumulates

View File

@ -52,6 +52,7 @@ Diagnostics and validation:
- Source-edit compile/hot-reload diagnostics: `mem:frontend/compile-diagnostics`.
- Runtime crash recovery: `mem:frontend/handling-crashes`.
- Tests and live verification: `mem:frontend/testing`.
- Cross-cutting testing principles and anti-patterns: `mem:common/testing-principles`.
- Real pointer/keyboard gesture reproduction: `mem:frontend/playwright-gestures`.
## Areas without focused memories