test-writer

Generates unit, integration, and end-to-end tests using frameworks like pytest, Jest, JUnit, and Playwright. Use when the user needs to write tests for existing code, create test suites for a module, add edge-case coverage, or set up a testing framework from scratch.

261 stars

Best use case

test-writer is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. Generates unit, integration, and end-to-end tests using frameworks like pytest, Jest, JUnit, and Playwright. Use when the user needs to write tests for existing code, create test suites for a module, add edge-case coverage, or set up a testing framework from scratch.

Generates unit, integration, and end-to-end tests using frameworks like pytest, Jest, JUnit, and Playwright. Use when the user needs to write tests for existing code, create test suites for a module, add edge-case coverage, or set up a testing framework from scratch.

Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.

Practical example

Example input

Use the "test-writer" skill to help with this workflow task. Context: Generates unit, integration, and end-to-end tests using frameworks like pytest, Jest, JUnit, and Playwright. Use when the user needs to write tests for existing code, create test suites for a module, add edge-case coverage, or set up a testing framework from scratch.

Example output

A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.

When to use this skill

  • Use this skill when you want a reusable workflow rather than writing the same prompt again and again.

When not to use this skill

  • Do not use this when you only need a one-off answer and do not need a reusable workflow.
  • Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/test-writer/SKILL.md --create-dirs "https://raw.githubusercontent.com/partme-ai/full-stack-skills/main/skills/dev-utils-skills/test-writer/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/test-writer/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How test-writer Compares

Feature / Agenttest-writerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generates unit, integration, and end-to-end tests using frameworks like pytest, Jest, JUnit, and Playwright. Use when the user needs to write tests for existing code, create test suites for a module, add edge-case coverage, or set up a testing framework from scratch.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

## When to use this skill

Use this skill whenever the user wants to:
- Write unit tests for functions, classes, or modules
- Create integration tests for API endpoints or database interactions
- Build end-to-end tests for user workflows
- Add test coverage for edge cases and error paths
- Set up a testing framework (pytest, Jest, JUnit, Vitest, Playwright)
- Generate test fixtures and mock data

## How to use this skill

### Workflow

1. **Identify the code under test** - Read the function/class/module to understand its behavior
2. **Choose the test type** - Unit (isolated), integration (multi-component), or E2E (full flow)
3. **Write tests using AAA pattern** - Arrange inputs, Act on the function, Assert expected results
4. **Cover edge cases** - Empty inputs, boundary values, error conditions, concurrent access

### Unit Test Example (pytest)

```python
import pytest
from decimal import Decimal
from orders import calculate_order_total, OrderItem

class TestCalculateOrderTotal:
    def test_single_item_no_discount(self):
        items = [OrderItem(price=Decimal("10.00"), quantity=2)]
        result = calculate_order_total(items, discount_pct=0.0, tax_rate=0.08)
        assert result == Decimal("21.60")

    def test_applies_discount_before_tax(self):
        items = [OrderItem(price=Decimal("100.00"), quantity=1)]
        result = calculate_order_total(items, discount_pct=0.1, tax_rate=0.10)
        assert result == Decimal("99.00")

    def test_empty_items_returns_zero(self):
        result = calculate_order_total([], discount_pct=0.0, tax_rate=0.08)
        assert result == Decimal("0.00")

    def test_invalid_discount_raises_error(self):
        items = [OrderItem(price=Decimal("10.00"), quantity=1)]
        with pytest.raises(ValueError, match="discount_pct must be 0-1"):
            calculate_order_total(items, discount_pct=1.5)
```

### Integration Test Example (Jest + Supertest)

```typescript
import request from 'supertest';
import { app } from '../src/app';
import { db } from '../src/database';

describe('POST /api/users', () => {
  afterEach(async () => { await db.query('DELETE FROM users WHERE email LIKE $1', ['%@test.com']); });

  it('creates a user and returns 201', async () => {
    const res = await request(app)
      .post('/api/users')
      .send({ name: 'Alice', email: 'alice@test.com' })
      .expect(201);
    expect(res.body).toMatchObject({ name: 'Alice', email: 'alice@test.com' });
  });

  it('returns 400 for missing email', async () => {
    await request(app).post('/api/users').send({ name: 'Bob' }).expect(400);
  });
});
```

## Best Practices

1. **One assertion per behavior** - Each test should verify one specific behavior
2. **Descriptive test names** - Name tests as `test_<behavior>_when_<condition>` or `it('should <outcome> when <input>')`
3. **Isolate dependencies** - Use mocks/stubs for external services, databases, and APIs
4. **Test the contract, not the implementation** - Assert on outputs and side effects, not internal state
5. **Run tests in CI** - Ensure tests pass on every commit; aim for 80%+ line coverage on critical paths

## Keywords

测试编写, test writing, unit test, integration test, e2e test, pytest, Jest, JUnit, Vitest, Playwright, mock, fixture, 单元测试, 集成测试, 端到端测试, test coverage

Related Skills

vitest

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vitest testing framework including fast test execution, Vite integration, component testing, mocking, and configuration. Use when the user asks about Vitest, needs to write fast unit tests, test Vue/React components, or configure Vitest with Vite projects.

pytest

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for pytest testing framework including test writing, fixtures, parametrization, mocking, and plugins. Use when the user asks about pytest, needs to write Python tests, use pytest fixtures, or configure pytest for Python projects.

webapp-testing

261
from partme-ai/full-stack-skills

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

vant-vue3

261
from partme-ai/full-stack-skills

Provides structured guidance for Vant of Vue 3.0. Use when the user needs Vant with Vue 3, asks about mobile UI components such as Button, Cell, Form, Dialog, Toast, Popup, ConfigProvider, theme customization, project setup, or wants to implement mobile-first interfaces with vant or van- components.

layui-vue3

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Layui Vue component library including components, layer dialogs, and utilities. Use when the user asks about Layui Vue, needs to use Layui components in Vue 3, or implement UI components.

element-plus-vue3

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Element Plus Vue 3 component library including installation, components, themes, internationalization, and API reference. Use when the user asks about Element Plus for Vue 3, needs to build Vue 3 applications with Element Plus, or customize component styles.

bootstrap-vue3

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Bootstrap Vue 3 component library including Bootstrap components, grid system, utilities, and Vue 3 integration. Use when the user asks about Bootstrap Vue 3, needs to use Bootstrap components in Vue 3, or implement responsive layouts.

vuex-vue2

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vuex 2.x state management in Vue 2 applications including state, mutations, actions, getters, modules, and plugins. Use when the user asks about Vuex for Vue 2, needs to manage state in Vue 2 applications, or implement Vuex patterns.

vue3

261
from partme-ai/full-stack-skills

Guidance for Vue 3 using the official guide and API reference. Use when the user needs Vue 3 concepts, patterns, or API details to build components, apps, and tooling.

vue2

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vue 2.x development including Options API, components, directives, lifecycle hooks, computed properties, watchers, Vuex state management, and Vue Router. Use when the user asks about Vue 2, needs to create Vue 2 components, implement reactive data binding, handle component communication, or work with Vue 2 ecosystem tools.

vue-router

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vue Router including route configuration, navigation, dynamic routes, nested routes, route guards, programmatic navigation, and route meta. Use when the user asks about Vue Router, needs to set up routing, implement navigation guards, handle route parameters, or manage route transitions.

vue-router-v4

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vue Router v4 including route configuration, navigation, nested routes, route guards, and Vue 3 integration. Use when the user asks about Vue Router v4, needs to set up routing for Vue 3 applications, implement navigation guards, or work with Vue Router v4 features.