unit-testing

Write unit tests with AAA structure, mocking, parameterized cases, and coverage targets in Python, TypeScript, and Go.

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/MARUCIE/openclaw-foundry --skill unit-testing-marucie
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: unit-testing
Source: https://github.com/MARUCIE/openclaw-foundry/tree/main/web/public/packs/spellbook-test-engineer/skills/unit-testing
Command: npx skills add https://github.com/MARUCIE/openclaw-foundry --skill unit-testing-marucie

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing unit tests that are fast, isolated, and maintainable is hard: tests often couple to implementation details, leak shared state, mock the wrong boundaries, or chase meaningless coverage numbers. This Skill provides structured guidance for writing reliable unit tests across Python, TypeScript, and Go. ## Core Features & Use Cases - Test Structure & Naming: Enforces the Arrange-Act-Assert pattern with per-language naming conventions for pytest, Jest/Vitest, and Go's testing package. - Mocking & Test Doubles: Covers stubs, mocks, spies, and fakes with concrete examples using unittest.mock, pytest-mock, jest.fn, vi.spyOn, Go interface mocking, in-memory repositories, and HTTP stubbing via responses, msw, and httptest. - TDD & Coverage Strategy: Guides the red-green-refactor cycle, parameterized/table-driven tests, and realistic line/branch coverage targets with tool configuration for pytest-cov, Jest, Vitest, and go cover. - Use Case: When implementing a new pricing module in TypeScript, follow the TDD workflow to write a failing parameterized test first, mock the external tax API with msw, implement the logic, and verify 80% branch coverage before merging. ## Quick Start Ask the AI to write unit tests for your function following the AAA pattern, mocking external dependencies and covering edge cases and error paths.

Frequently Asked Questions about unit-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests with the AAA pattern?▼

Structure every test in three phases: Arrange sets up inputs and dependencies, Act calls the unit under test exactly once, and Assert verifies the outcome. Keep one logical assertion per test and name tests to describe the scenario and expected result.

How to mock external dependencies in Python, TypeScript, and Go tests?▼

Python uses unittest.mock or pytest-mock's mocker.patch, TypeScript uses jest.fn or vi.spyOn, and Go defines an interface for the dependency with a test struct implementing it. Mock only external boundaries like databases, HTTP, and filesystems, never the unit under test.

What is the difference between a mock, stub, spy, and fake?▼

A stub returns fixed values, a mock records calls for interaction verification, a spy wraps the real implementation while recording calls, and a fake is a lightweight working implementation like an in-memory repository. Use fakes for stateful dependencies and mocks for fire-and-forget side effects.

What code coverage percentage should I target?▼

Target 80% line and 70% branch coverage for greenfield projects, and 95% line with 90% branch for critical paths like payments and auth. Exclude generated code, migrations, and configuration loaders, and treat coverage as a floor rather than a goal.

Why are my tests flaky and how do I fix them?▼

Flakiness usually comes from shared mutable state between tests, execution-order dependencies, or time-based sleeps. Give each test its own fixtures, clean up with teardown hooks or t.Cleanup, and inject a clock abstraction instead of calling sleep.

When should I not use TDD?▼

TDD pays off most for new features with clear acceptance criteria, complex business logic, and regression prevention. It adds less value for exploratory spike code, UI layout work, and third-party integration spikes where integration tests are more appropriate.