testing-unit

Installation
SKILL.md

Purpose

This skill equips the AI to assist with unit testing using frameworks like Jest/Vitest for JavaScript, pytest for Python, Go's testify, RSpec for Ruby, XCTest for Swift, and JUnit5 for Java. It focuses on mocking dependencies, creating stubs, and ensuring test isolation to verify code behavior in controlled environments.

When to Use

Use this skill when writing new unit tests, debugging existing ones, or refactoring code that requires isolated testing. Apply it for TDD workflows, mocking external APIs or databases, or ensuring functions work independently. For example, use it when a function depends on a network call—mock it to test locally without real dependencies.

Key Capabilities

  • Mocking: Create mocks for functions or modules, e.g., in Jest with jest.mock('module') to replace real implementations.
  • Stubbing: Define stub responses, like in pytest using monkeypatch.setattr() to fake object methods.
  • Isolation: Run tests in isolation, such as using Go's testify to assert without side effects, or JUnit5's @TempDir for isolated file operations.
  • Framework-Specific: Support for Jest/Vitest assertions (e.g., expect().toBe()), pytest fixtures for setup/teardown, RSpec's double for mocks, XCTest's setUp() for isolation, and JUnit5's @Mock annotations.
  • Config Formats: Use Jest's jest.config.js with { testEnvironment: 'node', setupFilesAfterEnv: ['<rootDir>/setupTests.js'] } for custom mocks; pytest's pytest.ini with [pytest] addopts = -v for verbose output.

Usage Patterns

To accomplish unit testing tasks, follow these steps: 1) Identify dependencies to mock (e.g., HTTP calls). 2) Set up mocks or stubs in your test file. 3) Write assertions to verify outputs. 4) Run tests with appropriate flags. For TDD, write a failing test first, then implement code. In Jest, structure tests with describe() blocks; in pytest, use fixtures for shared setup. Always isolate tests by avoiding global state—use beforeEach() in Jest or @pytest.fixture(scope='function') in pytest.

Related skills
Installs
20
GitHub Stars
5
First Seen
Mar 7, 2026