Agent skill
unit-testing
Write comprehensive unit tests for code. Use when asked to (1) write tests for new or existing code, (2) add unit tests, (3) test a function/module/class, (4) verify code still works after changes, (5) create test coverage, or when phrases like "write tests", "add tests", "test this", "make sure this works" appear. Supports Python, JavaScript, R, Rust, Go, C++, SQL, Bash, Ansible, Kubernetes/Kustomize, Docker, and Docker Compose.
Install this agent skill to your Project
npx add-skill https://github.com/jaredlander/freshbooks-speed/tree/main/.claude/skills/unit-testing
SKILL.md
Unit Testing Skill
Write comprehensive unit tests with full coverage: happy paths, edge cases, and error conditions.
Core Principles
- Test behavior, not implementation - Tests verify what code does, not how
- One assertion concept per test - Each test validates a single logical behavior
- Arrange-Act-Assert structure - Setup, execute, verify
- Descriptive test names - Name describes scenario and expected outcome
- Independent tests - No test depends on another's state or execution order
- Fast tests - Mock expensive operations (network, disk, databases) unless integration testing
Workflow
0. MANDATORY: Use context7 Before Writing Tests
CRITICAL: Before writing ANY tests, use context7 to look up current testing framework documentation and best practices.
Always use context7 to verify:
- Testing framework APIs (Jest, Vitest, pytest, etc.)
- Assertion syntax and available matchers
- Mocking/stubbing patterns
- Testing library utilities (React Testing Library, etc.)
- Framework-specific best practices
Process:
- Identify testing framework and libraries in use
- Use
context7 resolve <framework>for each - Query relevant topics: assertions, mocking, async testing, etc.
- Review docs before writing test code
Example:
context7 resolve vitest
context7 get-library-docs --library vitest --topic "mocking"
context7 resolve @testing-library/react
context7 get-library-docs --library @testing-library/react --topic "async"
Workflow Steps
- Use context7 for testing framework docs - Look up current API and patterns
- Analyze the code - Identify public interfaces, dependencies, edge cases, error conditions
- Determine test scope - Unit tests for functions/classes, integration tests for interactions
- Check existing structure - Follow project's existing test organization patterns
- Select appropriate framework - See language-specific references below
- Write comprehensive tests covering:
- Happy path (expected inputs produce expected outputs)
- Edge cases (empty inputs, boundaries, null/None values)
- Error conditions (invalid inputs, exceptions, failure modes)
- State changes (side effects, mutations)
context7 Usage by Language/Framework
Before writing tests, use context7 to look up documentation for:
| Language/Framework | context7 Libraries to Query |
|---|---|
| JavaScript/React | react, vitest or jest, @testing-library/react |
| Python | pytest, relevant libraries being tested |
| R | testthat, tidyverse |
| Rust | rust (built-in testing) |
| Go | go (testing package) |
| C++ | googletest or gtest |
| Node.js/Express | express, supertest, jest |
Common topics to query:
- "mocking", "assertions", "async testing", "setup teardown"
- "matchers", "fixtures", "test coverage", "integration tests"
Language References
Select the appropriate reference based on the code being tested:
| Language/Tool | Reference | Framework |
|---|---|---|
| Python | python.md | pytest |
| JavaScript | javascript.md | Jest / Vitest |
| R | r.md | testthat |
| Rust | rust.md | built-in #[test] |
| Go | go.md | testing + testify |
| C++ | cpp.md | Google Test |
| SQL (PostgreSQL) | sql.md | pgTAP |
| Bash | bash.md | bats-core |
| Ansible | ansible.md | Molecule + ansible-lint |
| Kubernetes/Kustomize | kubernetes.md | kubeconform + conftest |
| Docker | docker.md | hadolint + container-structure-test |
Test Organization
Follow each language's conventions. When a project has existing tests, match their structure.
Mocking Strategy
Mock external dependencies based on context:
- Always mock: Network calls, external APIs, system time
- Consider mocking: Databases (use test DB or mock based on test type), file system
- Rarely mock: Pure functions, data transformations
Coverage Targets
Aim for comprehensive coverage:
- All public functions/methods
- All code branches (if/else, match arms, error handlers)
- Boundary conditions
- Error handling paths
REMINDER: Always Use context7
Before writing any test code:
- Use context7 to look up the testing framework's current API
- Verify assertion syntax and available matchers
- Check mocking/stubbing best practices
- Review async testing patterns if needed
Never write tests from memory alone - always verify with current documentation using context7.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
javascript-react
Expert-level JavaScript and React development. Use when asked to (1) write JavaScript code requiring advanced patterns like closures, proxies, generators, or async iterators, (2) build React applications with hooks, context, suspense, or server components, (3) optimize JavaScript/React performance, (4) implement complex state management, (5) write TypeScript with advanced type patterns, or when phrases like "React component", "JavaScript function", "TypeScript", "hooks", "state management", "frontend", "web app" appear.
github-actions
code-review
Review code written by Claude Code or humans across multiple languages. Use when asked to review, audit, critique, or analyze code quality. Supports R, Python, JavaScript, SQL, C++, Rust, Go, Ansible, Kustomize/Kubernetes, Dockerfiles, Docker Compose, and Bash. Covers correctness, security, performance, testing, documentation, and architecture. Produces actionable output for Claude Code to fix issues plus human-readable REVIEW.md summaries.
html
Write semantic, accessible, performant HTML with modern best practices. Use when asked to (1) create HTML pages or documents, (2) write semantic markup, (3) improve accessibility, (4) optimize HTML structure and performance, (5) implement forms, tables, or complex layouts, or when phrases like "HTML page", "web page", "markup", "semantic HTML", "accessibility" appear.
css
Expert-level CSS development with modern features and best practices. Use when asked to (1) write or debug CSS, (2) implement layouts with flexbox, grid, or container queries, (3) create animations and transitions, (4) optimize CSS performance, (5) work with CSS preprocessors or CSS-in-JS, (6) implement responsive design, or when phrases like "style", "CSS", "stylesheet", "design", "layout", "animation" appear.
javascript-ember
Expert-level Ember.js development. Use when asked to (1) write Ember.js applications with components, services, routes, or controllers, (2) implement Ember Data models and adapters, (3) work with Ember Octane patterns (Glimmer components, tracked properties, modifiers), (4) optimize Ember application performance, (5) write Ember tests with QUnit or testing-library, or when phrases like "Ember component", "Ember route", "Glimmer", "tracked property", "Ember addon" appear.
Didn't find tool you were looking for?