unit-testing-framework — Claude Code skill: unit tests, AAA style
A skill that gives the agent rules for writing unit tests: Arrange-Act-Assert structure, mocks, edge cases. Useful when a function or class needs coverage.
npx skills add aj-geddes/useful-ai-prompts --skill unit-testing-framework -a claude-codeWhat unit-testing-framework does
The skill spells out how to write unit tests: one assertion per test, names that describe behaviour, external dependencies replaced with mocks. Inside there is a walkthrough of the AAA pattern on a JavaScript example with Jest, a table of reference guides in the references/ directory, and a do/don't list of practices.
The guides cover test structure, examples across languages, mocks and test doubles, async code and coverage, edge cases, and a complete test suite. The don't list is blunt about it: no tests that depend on each other, no assertions on implementation details, no real databases or APIs inside a unit test.
The skill is not tied to one framework — Jest, pytest, JUnit and RSpec all appear in the description. If your project already has its own test conventions, the agent will push them toward AAA and mocks, so it is worth comparing styles before installing.
What it helps with
- write tests for a new function or class
- raise coverage on critical code paths
- set one test style across a team
- refactor code with tests as a safety net
- work out how to mock external dependencies
Example prompts for the agent
- write unit tests for
UserService.createUserusing the AAA pattern - add edge case tests for the discount calculation function
- refactor this module, write the tests first
How to install unit-testing-framework
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill unit-testing-framework -a claude-code2Manually: put the files in place
~/.claude/skills/unit-testing-framework/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/unit-testing-framework/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill unit-testing-framework -a codex2Manually: put the files in place
.agents/skills/unit-testing-framework/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill unit-testing-framework -a cursor2Manually: put the files in place
.cursor/skills/unit-testing-framework/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install aj-geddes/useful-ai-prompts unit-testing-framework2Manually: put the files in place
.github/skills/unit-testing-framework/SKILL.md1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill unit-testing-framework -a gemini-cli2Platform CLI
gemini skills install https://github.com/aj-geddes/useful-ai-prompts --path skills/unit-testing-frameworkManually: put the files in place
.devin/skills/unit-testing-framework/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill unit-testing-framework -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about unit-testing-framework
How do I install unit-testing-framework in Claude?
Run npx skills add aj-geddes/useful-ai-prompts --skill unit-testing-framework -a claude-code. The skill lands in ~/.claude/skills/unit-testing-framework/SKILL.md.
What does unit-testing-framework do?
It gives the agent rules for unit tests: the Arrange-Act-Assert pattern, isolated tests, mocks for external dependencies, and edge case checks. The guides in references/ cover test structure, examples across languages, and async code.
Which test frameworks does the skill cover?
Jest, pytest, JUnit and RSpec are named in the description. The quick start example is JavaScript with Jest.
Source text
SKILL.md · MIT
---
name: unit-testing-framework
description: >
Write comprehensive unit tests with high coverage using testing frameworks
like Jest, pytest, JUnit, or RSpec. Use when writing tests for functions,
classes, components, or establishing testing standards.
---
# Unit Testing Framework
## Table of Contents
- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)
## Overview
Write effective unit tests that are fast, isolated, readable, and maintainable following industry best practices and AAA (Arrange-Act-Assert) pattern.
## When to Use
- Writing tests for new code
- Improving test coverage
- Establishing testing standards
- Refactoring with test safety
- Implementing TDD (Test-Driven Development)
- Creating test utilities and mocks
## Quick Start
Minimal working example:
```javascript
// Jest/JavaScript example
describe("UserService", () => {
describe("createUser", () => {
it("should create user with valid data", async () => {
// Arrange - Set up test data and dependencies
const userData = {
email: "[email protected]",
firstName: "John",
lastName: "Doe",
};
const mockDatabase = createMockDatabase();
const service = new UserService(mockDatabase);
// Act - Execute the function being tested
const result = await service.createUser(userData);
// Assert - Verify the outcome
expect(result.id).toBeDefined();
expect(result.email).toBe("[email protected]");
expect(mockDatabase.save).toHaveBeenCalledWith(
expect.objectContaining(userData),
);
});
});
});
```
## Reference Guides
Detailed implementations in the `references/` directory:
| Guide | Contents |
|---|---|
| [Test Structure (AAA Pattern)](references/test-structure-aaa-pattern.md) | Test Structure (AAA Pattern) |
| [Test Cases by Language](references/test-cases-by-language.md) | Test Cases by Language |
| [Mocking & Test Doubles](references/mocking-test-doubles.md) | Mocking & Test Doubles |
| [Testing Async Code](references/testing-async-code.md) | Testing Async Code, Test Coverage |
| [Testing Edge Cases](references/testing-edge-cases.md) | Testing Edge Cases |
| [Example: Complete Test Suite](references/example-complete-test-suite.md) | import { UserService } from "./user-service"; |
## Best Practices
### ✅ DO
- Write tests before or alongside code (TDD)
- Test one thing per test
- Use descriptive test names
- Follow AAA pattern
- Test edge cases and error conditions
- Keep tests isolated and independent
- Use setup/teardown appropriately
- Mock external dependencies
- Aim for high coverage on critical paths
- Make tests fast (< 10ms each)
- Use parameterized tests for similar cases
- Test public interfaces, not implementation
### ❌ DON'T
- Test implementation details
- Write tests that depend on each other
- Ignore failing tests
- Test third-party library code
- Use real databases/APIs in unit tests
- Make tests too complex
- Skip edge cases
- Forget to clean up resources
- Test everything (focus on business logic)
- Write flaky tests
© aj-geddes · MIT · aj-geddes/useful-ai-prompts