Skip to content
Back to skills

Writing Tests

ASecurity

Write and edit test files that model real user flows. Use when creating, modifying, or reviewing test files.

  • 883 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 27, 2026
developmentgoapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add saffron-health/libretto --skill writing-tests --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Writing Tests?

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

Security grade badge for Writing Tests
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/saffron-health-writing-tests/badge)](https://www.skillsdirectory.com/skills/saffron-health-writing-tests)

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
---
name: writing-tests
description: "Write and edit test files that model real user flows. Use when creating, modifying, or reviewing test files."
---

# Writing Tests

## Core Principle: Tests Are User Flows

Each test should represent a single, concrete flow that a real user would follow when interacting with the system. Write tests at the same abstraction level as the user experiences the system.

## Rules

### 1. Match the user's interface exactly

The test should call the system the same way a user would. If the system is a CLI, the test should invoke the CLI with argument strings. If it's a library, the test should call the public API. Don't wrap the interface in test-specific helpers that hide what's actually happening.

**Good** — the test reads like what a user would do:

```ts
const result = await librettoCli("setup --skip-browsers");
expect(result.exitCode).toBe(0);

const result2 = await librettoCli("--help");
expect(result2.stdout).toContain("Usage:");
```

**Bad** — extra abstraction obscures the actual interaction:

```ts
const result = await setupWithDefaults(); // hides the real CLI invocation
assertSuccess(result); // hides what "success" means
```

### 2. Keep tests verbose and concrete

Don't introduce helpers for brevity. The value of a test is that you can read it top-to-bottom and understand exactly what's happening. Repetition across tests is fine — each test should be self-contained and readable on its own.

### 3. One flow per test

Each test should exercise one coherent user scenario from setup through assertion. Don't combine unrelated flows into a single test, and don't split one logical flow across multiple tests.

### 4. Tests form a behavioral hull

The full set of tests for a system should cover the sufficiently complete set of flows a user might follow. Think about:

- The happy path for each major feature
- Edge cases a user would realistically hit
- Error cases and what the user sees when things go wrong

When adding a new feature, add tests that cover the new user flows it introduces. When fixing a bug, add a test that reproduces the flow where the bug occurred.

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…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.