$npx -y skills add pssah4/digital-innovation-agents --skill testingCreates and manages unit tests and integration tests. Analyzes the existing codebase, auto-detects the test framework, and generates tests that follow project conventions. Use this skill when the user mentions "write tests", "unit tests", "integration tests", "test coverage", "te
| 1 | # Testing -- Unit & Integration Tests |
| 2 | |
| 3 | Creates tests that fit into the existing codebase. Detects the |
| 4 | framework, patterns, and conventions automatically from the project. |
| 5 | |
| 6 | Writing style and frontmatter rules: |
| 7 | See `skills/project-conventions/SKILL.md#canonical-specs` (Writing style, |
| 8 | Frontmatter spec). |
| 9 | |
| 10 | ## MANDATORY Pre-Phase 0: Branch and item check |
| 11 | |
| 12 | Tests bind to a specific backlog item. Run the team-workflow check (full |
| 13 | rules: `skills/project-conventions/references/team-workflow.md`): |
| 14 | |
| 15 | 1. Identify the active item from the prompt or via AskUserQuestion; |
| 16 | tests usually continue on the same FEAT/FIX/IMP item branch. |
| 17 | 2. Verify the branch matches `feature/<item-id-lower>-<slug>`. On a |
| 18 | wrong branch, AskUserQuestion to switch. |
| 19 | 3. Skill-triggered GitHub integration (idempotent): |
| 20 | ``` |
| 21 | python3 tools/github-integration/flow.py create-issue --item <ID> |
| 22 | python3 tools/github-integration/flow.py open-draft-pr --item <ID> |
| 23 | ``` |
| 24 | 4. At Handoff Ritual end, tag the phase via |
| 25 | `python3 tools/github-integration/flow.py tag-phase --item <ID> --phase test`. |
| 26 | 5. Write `.git/dia-active-skill` so subsequent invocations stay silent. |
| 27 | |
| 28 | ## MANDATORY Phase 0: Artifact triage |
| 29 | |
| 30 | New tests bind to an existing FEATURE, IMP, or FIX id. **Exception:** |
| 31 | read-only analysis (coverage report, gap identification, reading |
| 32 | existing tests) does not need triage. |
| 33 | |
| 34 | If the binding cannot be derived from the prompt, ask once before the |
| 35 | first new test (user's working language): |
| 36 | |
| 37 | > "Does this test run belong to a FEATURE, an IMP, or a FIX? Please |
| 38 | > name the ID." |
| 39 | |
| 40 | Triage details: |
| 41 | `skills/project-conventions/references/graph-invariants.md`, section |
| 42 | "Artifact triage at entry point". |
| 43 | |
| 44 | ## MANDATORY: Verify gate language |
| 45 | |
| 46 | `/testing` shares the verify gate with `/coding`. No completion claim |
| 47 | without fresh verification evidence in the current message. |
| 48 | |
| 49 | Hard threshold for "all green": 0 test failures, 0 lint errors (if lint |
| 50 | runs in the suite), coverage not regressed (line/branch/function each at |
| 51 | or above the project target from `_devprocess/rules/technical.md` or |
| 52 | Coverage section). |
| 53 | |
| 54 | Forbidden without fresh verification: "should pass", "tests should be |
| 55 | green now", "looks good", "probably fine". The skill executes the test |
| 56 | command IN THIS MESSAGE before any completion claim. Cached output and |
| 57 | stale logs are not evidence. |
| 58 | |
| 59 | ## Codebase analysis first |
| 60 | |
| 61 | Before writing tests, scan the project for: |
| 62 | |
| 63 | - Test framework and config (package.json scripts/devDeps, pyproject.toml, Cargo.toml, existing test files) |
| 64 | - Test location and naming (tests/, __tests__/, .test.ts vs .spec.ts vs _test.py, conftest.py, fixtures) |
| 65 | - Conventions in use (mocking style, async handling, assertions, shared helpers, untested areas) |
| 66 | |
| 67 | This is internal analysis; do not write back into FEATURE/BACKLOG. Adopt the |
| 68 | patterns the project already uses. Do not introduce new frameworks unless |
| 69 | the project has none. |
| 70 | |
| 71 | ## Priority order |
| 72 | |
| 73 | Unit > integration > e2e, scope-aware. Focus of this skill: integration tests |
| 74 | (primary) and unit tests (TDD fallback or gap-filling). E2E is a separate topic. |
| 75 | |
| 76 | ## Role alongside TDD |
| 77 | |
| 78 | When `/coding` runs in TDD mode (see `coding/SKILL.md` Phase 3b), unit |
| 79 | tests already exist. `/testing` then focuses on, in priority: |
| 80 | |
| 81 | 1. **Integration tests (primary).** Multi-module flows: API endpoints, |
| 82 | DB access, event/message flows, external integrations with mocked |
| 83 | boundaries. |
| 84 | 2. **Unit test gaps (secondary).** Edge cases, error paths, boundary |
| 85 | conditions missed by the RED tests. |
| 86 | 3. **Coverage check (tertiary).** Report against targets; gaps listed, |
| 87 | not auto-filled. |
| 88 | |
| 89 | If `/coding` ran without TDD, `/testing` also creates the unit tests |
| 90 | following AAA and FIRST. |
| 91 | |
| 92 | ## Unit Tests |
| 93 | |
| 94 | **When.** Public functions with logic, utilities, data transformations, |
| 95 | error handling. Skip trivial getters/setters and pure pass-throughs. |
| 96 | |
| 97 | ### AAA Pattern (Arrange, Act, Assert) |
| 98 | |
| 99 | Every test follows the AAA shape: |
| 100 | |
| 101 | - Arrange: build inputs, fixtures, mocks |
| 102 | - Act: invoke the unit under test once |
| 103 | - Assert: check return value, state change, or thrown error |
| 104 | - One behavior per test; name it after the behavior, not the method |
| 105 | |
| 106 | Match the project's existing assertion verbosity; do not add `// Arrange` |
| 107 | comments unless they already exist. |
| 108 | |
| 109 | ### FIRST Principles |
| 110 | |
| 111 | Fast (<1s/test), Independent, Repeatable, Self-validating, Timely. |
| 112 | |
| 113 | ### Per-function checklist |
| 114 | |
| 115 | Full version: `references/test-checklist.md`. Short version: happy path, |
| 116 | edge cases (empty/null/undefined/boundary), error cases (invalid inputs, |
| 117 | missing dependencies), boundary conditions (min/max, |