test-quality
The test-quality Claude Code skill enforces best practices for writing reliable, readable, and maintainable test code by validating Arrange-Act-Assert structure, single-behavior focus, assertion quality, test isolation, meaningful naming conventions, and proper test data management. Use this skill when generating or reviewing tests, or whenever a user requests test creation, test improvements, test reviews, or guidance on test structure and quality standards.
git clone --depth 1 https://github.com/techygarg/lattice /tmp/test-quality && cp -r /tmp/test-quality/skills/atoms/test-quality ~/.claude/skills/test-qualitySKILL.md
# Test Quality ## Config Resolution Skill support project custom. Order: 1. Look `.lattice/config.yaml` in repo root 2. If find, check `paths.test_quality` for custom doc path 3. If custom path exist, read doc & check YAML frontmatter for `mode`: - **`mode: override`** (or no mode): Custom doc take full control. Use instead default. Must be complete -- is only reference. - **`mode: overlay`**: Read `./references/defaults.md` first, then apply custom doc on top. Custom sections replace match sections (by heading). New sections add after. 4. If no config/path/file, read `./references/defaults.md` 5. **Language adaptation**: If `paths.language_idioms` exist in config, read **"Testing Patterns"** section and adapt §5 (Test Naming), §4 (Test Isolation), §6 (Test Data Builders) to language test framework idioms. Language idioms take precedence over pseudocode defaults. Defaults ship w/ skill. Work out-of-box. Override only when team have different standards. ## Self-Validation Checklist STOP after gen each test. Check ALL before continue. If fail, fix. If ambiguous (see Ambiguity Signals), flag -- show options & reasoning. 1. **AAA STRUCTURE**: arrange, act, assert separate w/ blank lines? Any logic (if/loop/try) in arrange or assert? 2. **SINGLE BEHAVIOR**: Test verify one behavior per loaded doc (default: one behavior per test, name need "and" = split)? 3. **ASSERTION QUALITY**: Assert observable behavior, not implementation? Specific enough catch regression? 4. **ISOLATION**: Test depend other test output/effects? All mutable state per-test? 5. **TEST NAME**: Name follow team convention per loaded doc (default: describe behavior, not method)? Failure message clear? 6. **TEST DATA**: Complex arrange uses builders/factories? Magic values → named constants? (Inline literals fine for trivial tests.) 7. **MOCK BOUNDARIES**: Mock per loaded doc (default: only at arch boundaries — I/O, external — not internal collab)? 8. **TEST CODE AS FIRST-CLASS**: Structured like production code? Shared constants at top, helpers extracted, no dead code, clear file organization? Project-specific checks: if loaded doc contains a validation checklist section, apply those after base checklist. ## Active Anti-Pattern Scan After checklist, scan these. If find, fix before present. - [ ] **Test-per-Method**: One test per method regardless behaviors → One test per scenario, named for behavior - [ ] **Assertion Roulette**: Multiple unrelated asserts; unclear which broke → Split to one behavior per test - [ ] **Shared Mutable State**: Pass alone, fail together → Isolate state; per-test setup; no static mutable - [ ] **Testing Implementation Details**: Break on refactor w/ same behavior; mock call counts → Assert observable behavior, not method calls - [ ] **Mystery Guest**: Depend external file/db/env var not visible → Inline data or use builders; all preconditions visible - [ ] **Slow Tests by Default**: Unit suite take minutes; hit db/network/fs → Mock/fake I/O; use in-memory - [ ] **Conditional Test Logic**: Test have if/loop/try -- test need own tests → Remove logic; use parameterized; let asserts fail natural - [ ] **Copy-Paste Tests**: Near-identical w/ small changes → Extract shared setup to builders; use parameterized ## Class-Level Review Fire when: (1) completing all tests for a class — new or existing. (2) adding or editing any test in an existing class. STOP before present. Per-test checks verify individual quality. This review verifies the test suite covers the class contract. ### Full review (new class or significant additions) 1. **Behavior inventory** — list every public method/behavior in class under test. If class not available, ask user to enumerate. 2. **Coverage matrix** — map each test → behavior it covers. Behaviors with zero tests → **blocking**. Do not present until user addresses gap or explicitly accepts it. 3. **Error path check** — scan class under test for: explicit throws, conditional error branches, edge guards. For each found: does a test exercise this path? If not → flag by name. Zero-coverage error paths are blocking unless user explicitly accepts. 4. **Behavioral duplication** — compare "then" clauses across all tests. Same observable outcome regardless of structural differences → flag as likely duplication. Name both tests. 5. **Balance signal** — any behavior with tests but none covering a failure or edge case → surface as question, not hard failure: "`deleteUser` has 1 test (happy path only) — does it have error cases?" ### Edit-scoped review (adding or changing one test in existing class) Run steps 3–5 only, scoped to the changed test: - Does this test duplicate the observable outcome of any existing test? - Does it cover a behavior or error path not previously covered? ## Ambiguity Signals Multiple valid outcomes. Present options, not choose silent. - **Unit vs Integration**: Service coordinate components -- test isolate (mock) or real collab? Depend coupling & what verify. - **Mock Depth**: Mock direct depend or let call through? Over-mock test implementation; under-mock create slow/flaky. - **Test Granularity**: One test multi asserts vs multi tests one assert? When asserts verify facets same behavior, group ok. ## Test Code as First-Class Code Test classes deserve same structural care as production code. They are living documentation -- readers spend as much time here as in source. **Treat test files like production classes:** - Shared constants and boundary values at top of file (named, not magic) - Shared builders/factories extracted to helpers -- not copy-pasted per test - Setup methods or fixtures for repeated arrange patterns - Logical grouping: related behaviors together (by feature, by scenario type) - Dead tests removed, not commented out - Refactoring applies: extract method when arrange is long, rename when intent unclear, move shared setup when duplicated **Refactoring opportunities to surface proactively:** - Multiple tests repeat same
Audit and fix all Lattice documentation, README, docs/, GitHub issue templates, and CLAUDE.md to ensure they are fully aligned with the current skill inventory. Documentation drift is the most common source of user confusion in Lattice — a skill exists in the codebase but not in the docs, or a renamed skill leaves a stale reference in the bug report template. If you've made any change to skills/ and haven't run this, run it now. Use when the user says 'align docs', 'audit docs', 'update documentation', 'skill align', 'check docs are in sync', 'audit skill inventory', 'ensure docs are aligned', 'are the docs up to date', or 'what needs updating'. Standalone — does not call other skills.
Create a new Lattice skill — atom, molecule, or refiner — following all framework conventions. Writing skill files manually almost always produces convention violations: wrong section order, missing confirmation gates, defaults.md without the right structure. This skill knows all of that and guides you through it. Use whenever adding any new atom, molecule, or refiner to Lattice, or when the user says 'create a new skill', 'add an atom', 'add a molecule', 'add a refiner', 'build X for Lattice', 'new lattice skill', or 'skill forge'. Does not validate, align docs, or deploy — those are separate skills you run after.
Deep behavioral audit of a Lattice skill — proposes 3 review personas relevant to the skill, runs independent scenario analysis from each persona's perspective, then merges only the high-confidence, practical findings into a severity-ordered gap report with proposed fixes. Structural validation (conventions, cross-references) is skill-validate's job — this skill finds gaps that would realistically surface when someone actually uses the skill: missing scenario handling, ambiguous instructions, silent failure cases, and behavioral inconsistencies. Filters out theoretical edge cases, low-likelihood speculation, and findings owned by other skills. Use after writing or significantly changing any skill, or when the user says 'review this skill', 'deep review', 'does this skill work', 'find gaps in this skill', 'stress test this skill', 'review from different angles', or 'skill review'. Standalone — does not call other skills.
Validate any Lattice SKILL.md against all tier conventions — atoms, molecules, and refiners. Catches structural errors, broken cross-references, and convention violations before they reach the repo. If you just wrote or modified a Lattice skill file and haven't run this yet, run it now — manual review consistently misses the same categories of errors this skill is specifically designed to catch. Use when the user says 'validate this skill', 'check this skill', 'does this follow conventions', 'review this skill file', 'check my SKILL.md', or 'skill validate'. Reports PASS/FAIL with specific file-and-section findings and actionable fixes. Standalone — does not call other skills.
Architectural thinking partner for an existing repository — scans the codebase, conducts a structured interview, agrees on current architectural state and recommended direction, and produces a shareable insights document. Scoped to one repository, module, or folder. Does not execute transformation — it orients. Use when the user says 'assess my codebase architecture', 'what direction should my codebase go', 'architecture compass', 'understand my architecture', 'audit architecture drift', 'architectural assessment', or 'help me understand what is wrong with my codebase'.
Facilitate a structured conversation to define architecture principles for a repository. Supports multiple architecture styles: clean architecture (default), hexagonal / ports & adapters, modular monolith, or custom. Produces a formal architecture document that the corresponding atom will use. Use when setting up a new project, defining architecture standards, or when the user says 'setup architecture', 'define layers', 'architecture principles', 'help me define my architecture', 'hexagonal architecture', 'modular monolith', 'ports and adapters', or 'define my architecture style'.
Enforce architectural rules when generating or modifying code. Defaults to clean architecture; supports any architecture style via the architecture-refiner. Validates layer responsibilities, dependency direction, and structural constraints using the loaded architecture rules. Use when generating code, reviewing architecture, creating new files, or when the user mentions 'architecture', 'layers', 'structure', 'dependency rules', 'hexagonal architecture', 'ports and adapters', 'modular monolith', or 'onion architecture'. Also use when reviewing generated code for structural compliance.
Investigate, reproduce, and safely fix a bug with regression protection. Composes context, diagnosis, architecture, code quality, and testing guardrails into a reproduce-first repair workflow. Use when the user says 'fix this bug', 'debug this', 'investigate this failure', 'patch this regression', 'repair this issue', or 'why is this broken'.