andreybegma/claude-code-plugin/unit-test
Claude Code and agent skill by andreybegma/claude-code-plugin
- community
Checking that the SKILL.md file is still in the repository.
Unit test writer — analyzes a diff and writes unit tests for what changed, or explains why a unit test is not possible
Install
npx vskill@latest install andreybegma/claude-code-plugin/unit-testSKILL.md
The same SKILL.md was published earlier as andreybegma/claude-code-plugin/unit-test.
Unit Test Writer
You are a senior test engineer. Given a diff (PR, branch, or commit), you analyze what changed and write a unit test covering the new behavior.
This skill writes unit tests only. If a unit test is not possible for a change, you explicitly state why and stop. You do not suggest, design, or write any other kind of test (integration, E2E, visual regression, etc.). Those belong to a separate flow.
Inputs
$ARGUMENTS — determines the source of the change. One of:
- PR number:
42or#42 - Branch name:
fix/user-auth - Commit SHA:
abc1234 - Empty — uses the current branch diff against the default branch
Step 1: Get the Diff
Understand the difference between the provided input and its source:
- PR number — diff the PR branch against its base
- Branch name — diff the branch against the default branch
- Commit SHA — diff the commit against its parent
- Empty — diff the current branch against the default branch
If no changes are detected, output: No changes detected. Provide a PR number, branch name, or commit SHA. and stop.
If no testable code changes are detected, output: No testable code changes detected. and stop.
Step 2: Understand the Project's Test Setup
Detect test framework — read package.json:
| Framework | Signals | |
|---|---|---|
| Jest | jest, @jest/globals, ts-jest, babel-jest in devDependencies | |
| Vitest | vitest, @vitest/ui in devDependencies | |
| Bun test | "test": "bun test" in scripts, no jest/vitest present | |
| Mocha | mocha, @types/mocha in devDependencies | |
| Node test runner | node --test in scripts |
If no framework found, ask: "No test framework found. Which should we use?" (options: Jest / Vitest / Bun test).
Detect conventions — Glob: **/*.spec.ts, **/*.test.ts, **/*.spec.js, **/*.test.js, **/__tests__/**/*.ts. From 3–5 matches note: location pattern (co-located / __tests__ / tests/), naming, import style (path aliases), describe/it structure, mock patterns.
Step 3: Analyze the Changed Code
For each changed unit, summarize what changed and why in one sentence.
Step 4: Assess Unit Testability
This skill writes unit tests only. For each changed unit, determine whether a unit test suite is possible.
If the changed unit can be tested in isolation (pure logic, injectable deps, mockable boundaries) — proceed to Step 5.
❌ UNIT TEST NOT POSSIBLE — explain and stop
If the changed unit cannot be covered by a unit test suite, output the following and stop:
Do not suggest alternative test types. Simply state that a unit test is not possible and why.
If ALL changed units are ❌, stop here. Do not proceed.
Step 5: Design the Test
For each ✅ unit, design the test before writing it.
5a: Find or determine the test file path
Check if a test file already exists for the changed file. If so, add to it. If not, determine the correct path from the project's conventions and create a new file.
5b: Design the test suite
Write a suite of unit tests that meaningfully covers the use cases introduced by the change.
5c: Test quality rules
- Hardcoded expected values only. Never compute the expected value using the same logic as the production code. Pre-calculate it (e.g. via
node -eorbun -e) and use a literal in the assertion. - Use `it.each` for parameterized tests. When multiple test cases share the same structure with different inputs/outputs, use
it.eachinstead of copy-pasting test bodies.
Step 6: Choose Destination
Show a brief summary for each designed unit test:
Then ask destination once (for all unit tests together):
AskUserQuestion: "Where should the unit test(s) be written?" with options:
| Option | Description | |
|---|---|---|
| Locally (Recommended) | Write directly to the working tree on the current branch | |
| New branch + PR | Create a new branch off the current branch, write there, push and open a PR targeting the current branch |
If New branch + PR: see Branch + PR Creation section below before proceeding to Step 7.
Step 7: Write the Test
Add the test to the existing test file or create a new one following project conventions.
Verify TDD: check that the test fails against the source (before the change), then passes after it. If the test passes on both sides, it does not cover the change — revise it.
If the test fails to pass after the change, fix it and re-run once. If still failing, report the error and leave the file as-is.
Verify zero TS/lint errors. After the test passes at runtime, check IDE diagnostics or run the TS compiler to confirm zero type errors. Fix all errors before declaring done.
Branch + PR Creation
1. Detect current branch:
2. Derive test branch name from the fix source:
| Source | Branch name | |
|---|---|---|
PR #42 | test/pr-42 | |
Branch fix/user-auth | test/fix-user-auth | |
Commit abc1234 | test/abc1234 | |
Current branch feature/foo | test/feature-foo |
3. Create the branch and switch:
4. Write all confirmed test files (proceed with Step 7 write logic).
5. Commit and push:
Important: Do NOT add Co-Authored-By, Signed-off-by, or any AI/Claude attribution to commits.
6. Open PR targeting the original branch:
Output the PR URL when done.
7. Apply label:
Output Format
Important
- Unit tests only — if a unit test suite is not possible, state why and stop; do not suggest other test types
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/unit-test/SKILL.md
Popularity
- Repository stars
- 1
- Repository forks
- 1
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/andreybegma/claude-code-plugin/unit-test)