Skip to content
Back to skills

Skill: Unit Testing (Cross-Cutting)

ASecurity

This skill is used to create unit tests for code components. Unit tests verify that individual functions, methods, or classes work correctly in isolation.

  • 26 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added February 7, 2026
developmentjavascriptpythongojavaphptestingdocumentation

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned February 12, 2026

npx -y skills add PolyXGO/HeraSpec --skill unit-test --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Skill: Unit Testing (Cross-Cutting)?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Skill: Unit Testing (Cross-Cutting)
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/polyxgo-skill-unit-testing-cross-cutting/badge)](https://www.skillsdirectory.com/skills/polyxgo-skill-unit-testing-cross-cutting)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Skill: Unit Testing (Cross-Cutting)

## Purpose

This skill is used to create unit tests for code components. Unit tests verify that individual functions, methods, or classes work correctly in isolation.

## When to Use

- When testing individual functions or methods
- When testing class methods in isolation
- When testing utility functions
- When testing business logic
- When testing data transformations
- When ensuring code correctness before integration

## Step-by-Step Process

### Step 1: Identify Test Targets
- Analyze the code to identify testable units
- List all public methods/functions
- Identify edge cases and boundary conditions
- Determine expected inputs and outputs

### Step 2: Set Up Test Framework
- Choose appropriate testing framework (Jest, PHPUnit, pytest, etc.)
- Configure test environment
- Set up test structure matching project conventions
- Ensure test framework is installed and configured

### Step 3: Write Test Cases
- Create test file matching source file structure
- Write tests for each function/method
- Test normal cases (happy path)
- Test edge cases (null, empty, boundary values)
- Test error cases (invalid input, exceptions)
- Use descriptive test names

### Step 4: Run and Verify
- Run tests to ensure they pass
- Check test coverage if available
- Refactor if needed
- Ensure tests are fast and isolated

### Step 5: Document Test Cases
- Add comments for complex test scenarios
- Document test data and expected outcomes
- Update test documentation if needed

## Required Input

- **Source code**: Code to be tested (functions, methods, classes)
- **Test framework**: Testing framework to use (Jest, PHPUnit, pytest, etc.)
- **Project structure**: Understanding of where tests should be placed
- **Dependencies**: List of dependencies that need to be mocked

## Expected Output

- Complete unit test files
- Tests covering normal, edge, and error cases
- Test assertions verifying expected behavior
- Test data and fixtures if needed
- Passing test suite

## Tone & Rules

### Test Naming
- Use descriptive names: `test_user_registration_with_valid_email()`
- Follow pattern: `test_<what>_<condition>_<expected_result>`
- Use clear, readable test names

### Test Structure
- Arrange: Set up test data and dependencies
- Act: Execute the code being tested
- Assert: Verify the results
- Clean up: Reset state if needed

### Coverage Goals
- Aim for high coverage of critical paths
- Test all public methods
- Test edge cases and error handling
- Don't test implementation details

### Limitations
- ❌ DO NOT test private methods directly (test through public interface)
- ❌ DO NOT write tests that depend on other tests
- ❌ DO NOT test external dependencies (use mocks)
- ❌ DO NOT write slow tests (use mocks for I/O)
- ❌ DO NOT test framework code

## Available Templates

- `templates/unit-test-template.js` - JavaScript/Jest template
- `templates/unit-test-template.php` - PHP/PHPUnit template
- `templates/unit-test-template.py` - Python/pytest template

## Available Scripts

- `scripts/generate-test-stubs.sh` - Generate test file stubs from source code

## Examples

See `examples/` directory for reference:
- `good-unit-test/` - Well-structured unit tests
- `bad-unit-test/` - Examples to avoid

## Links to Other Skills

- **integration-test**: Use after unit tests for integration testing
- **e2e-test**: Use for end-to-end testing
- **documents**: Use to document test strategy

Files in this skill

  • CHANGELOG.md3 KB
  • README-template.md1.4 KB
  • README.md1.8 KB
  • content-optimization-skill.md3 KB
  • data/charts.csv7.5 KB
  • data/colors.csv12.7 KB
  • data/landing.csv14.1 KB
  • data/pages-proposed.csv11.1 KB
  • data/pages.csv5 KB
  • data/products.csv29.1 KB
  • data/prompts.csv17 KB
  • data/stacks/flutter.csv10.2 KB
  • data/stacks/html-tailwind.csv11.1 KB
  • data/stacks/nextjs.csv12.3 KB
  • data/stacks/react-native.csv9.8 KB
  • data/stacks/react.csv12.7 KB
  • data/stacks/svelte.csv10.8 KB
  • data/stacks/swiftui.csv10.6 KB
  • data/stacks/vue.csv10.8 KB
  • data/styles.csv41 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…