oprogramadorreal/optimus-claude / skills/unit-test
unit-test
VerifiedImproves unit test coverage — discovers testing gaps and writes new tests that follow project conventions. Requires /optimus:init to have set up test infrastructure. Conservative — only adds new tests, never modifies existing test logic or source code; untestable code is flagged for /optimus:refactor. For an automated multi-cycle coverage loop, use /optimus:deep coverage.
| File | Kind | Size |
|---|---|---|
| README.md | markdown | 4.2 KB |
| SKILL.md | skill md | 8.2 KB |
| agents/openai.yaml | config | 198 B |
| agents/test-infrastructure-analyzer.md | markdown | 4.0 KB |
README.md
View on GitHub# optimus:unit-test
A [Claude Code](https://docs.anthropic.com/en/docs/claude-code) skill that improves unit test coverage for existing code — discovering gaps and generating tests that follow your project's conventions. Requires `/optimus:init` to have set up test infrastructure first.
**Conservative by design** — only adds new tests (new files, or new cases appended to existing test files), never refactors or restructures existing source code. If code is untestable as-is, it flags it rather than changing it; restructuring is the domain of `/optimus:refactor`.
## Features
- **Scope-aware discovery** — surveys test infrastructure, runs the existing suite, measures baseline coverage, and classifies code testability inline for small or path-scoped projects, delegating substantial surveys to a reconnaissance subagent (git submodules excluded)
- **Achievable threshold estimation** — sets a realistic coverage target reachable without refactoring
- **Prioritized test plan** — up to 10 items per run, highest-value targets first, user-approved before execution
- **Broken baseline handoff** — stops with a triage pointer when pre-existing tests fail; never fixes them
- **Bug discovery** — bugs found in existing code are reported, not fixed
- **Monorepo & multi-repo workspace support** — processes each initialized repo/subproject independently
## Usage
- `/optimus:unit-test` — full project
- `/optimus:unit-test src/api` — scope to a directory or subproject
For an automated multi-cycle loop that alternates test generation with testability refactoring, use `/optimus:deep coverage`.
## When to Run
- After `/optimus:init` — establish coverage for a newly initialized project
- On established codebases that grew without systematic testing
- Before releases, or after major refactors
- Periodically — coverage improves incrementally (up to 10 plan items per run)
## How It Works
1. Verifies project context exists and loads guideline docs (`coding-guidelines.md`, `testing.md`)
2. Runs Test Infrastructure Analyzer discovery inline or delegates it by scope: suite run, coverage baseline, testability classification — stops if no framework is found or the baseline is red
3. Presents a prioritized test plan (capped at 10 items) for approval
4. Writes tests following project conventions and mocking discipline; each test runs immediately, failing tests are fixed (test only, max 3 attempts) or reverted
5. Runs the full suite as a regression gate, then reports coverage impact, bugs discovered, and code flagged as untestable
## Relationship to Other Skills
| Skill | Role |
|---|---|
| `/optimus:init` | Installs the framework, coverage tooling, and testing docs this skill requires |
| `/optimus:refactor testability` | Restructures the code this skill flags as untestable |
| `/optimus:deep coverage` | Automated loop alternating this skill with testability refactoring |
| test-guardian agent | Passive complement — flags coverage gaps after code changes but writes no tests |
**Typical cycle**: `/optimus:init` → `/optimus:unit-test` → `/optimus:refactor testability` → `/optimus:unit-test` again.
## Skill Structure
| File | Purpose |
|---|---|
| `SKILL.md` | Skill definition with 5-step workflow |
| `agents/test-infrastructure-analyzer.md` | Discovery/coverage/testability subagent prompt |
| *(shared)* `references/shared-agent-constraints.md` | Base agent constraints prepended at dispatch |
| *(shared)* `references/agent-architecture.md` | Prompt assembly rule for subagent dispatch |
| *(shared)* `references/coverage-harness-mode.md` | Single-pass protocol under `/optimus:deep coverage` |
| *(shared)* `init/references/multi-repo-detection.md` | Workspace detection (only when cwd is outside a Git working tree) |
| *(shared)* `init/references/project-detection.md` | Monorepo structure detection (only when unclear) |
| *(shared)* `tdd/references/testing-anti-patterns.md` | Mocking discipline (read before mock-dependent tests) |
## Requirements
- Optimus installed in a [supported host](../../README.md#supported-hosts-and-versions)
- Git
- Project initialized with `/optimus:init` (required — the skill stops if `.claude/CLAUDE.md` is not found)
- Test command in `.claude/CLAUDE.md` if you want to use `/optimus:deep coverage`
## License
[MIT](../../LICENSE)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |