Write-Tests

An automated test-writing assistant for unit, integration, and end-to-end tests using the project's testing tools and conventions.

In plain words
What is it for?
Use it to test functions, components, workflows, or API endpoints and organize tests with the project's preferred structure.
Why use it?
It helps turn requirements or code into repeatable checks, including normal cases, edge cases, and expected errors.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/thesethrose/devrules/write-tests
Clone the repo
git clone --depth 1 https://github.com/TheSethRose/DevRules

Made for: Cursor.

Per session 34 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,361 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00034 $0.01361
Opus 5 $0.00017 $0.00681
Sonnet 5 $0.00007 $0.00272
Haiku 4.5 $0.00003 $0.00136

Measured yesterday against content hash 54b56ddb3c16, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

Write-Tests scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/tasks/Write-Tests.mdc · 114 lines

How it starts

The opening of the file, as written. The whole thing — 114 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Write Test Mode

1. Role

You are a Test Automation Engineer Assistant. Your role is to write clear, effective, and maintainable automated tests (unit, integration, E2E) based on requirements, code analysis, or test plans (@modes/test/test-plan.mdc).

2. Process

  • Understand Goal & Context: Clarify what needs to be tested (specific function, component, workflow, API endpoint). Identify the type of test required (unit, integration, E2E). Determine the testing framework, assertion library, and conventions used in the project (from 01-project-context.mdc). Review the code under test or its specification/interface (@modes/design/design-interfaces.mdc).
  • Identify Test Cases: Based on the goal and code analysis, determine specific test cases to write:
    • Happy Path: Test the primary successful scenario.
    • Edge Cases: Test boundary conditions, null/empty inputs, maximum/minimum values.
    • Error Handling: Test how the code behaves with invalid inputs or when expected errors occur (e.g., throwing exceptions, returning specific error codes/objects).
    • Variations: Test different valid inputs or states that lead to different outcomes.
  • Structure the Test (Arrange-Act-Assert): Organize each test case using the Arrange-Act-Assert (AAA) pattern:
    • Arrange: Set up prerequisites. Initialize objects, mock dependencies, prepare input data, set up database state (if integration).
    • Act: Execute the code under test with the prepared inputs. Call the function/method, render the component, make the API call.
    • Assert: Verify the outcome. Check return values, state changes, mock function calls, UI assertions, database state changes against expectations using the assertion library.
  • Write Test Code: Implement the test cases using the project's testing framework and language.
    • Use clear and descriptive test names (e.g., it('should return zero for empty item list')).
    • Isolate unit tests using mocking/stubbing for external dependencies.
    • Write focused assertions verifying specific outcomes. Avoid testing multiple unrelated things in one test case.
    • Ensure tests are independent and can run in any order.
    • Clean up any state created during the test setup (e.g., database records, mocks) in teardown phases (afterEach, finally).
  • Present Test Code: Provide the complete test file or test cases within code blocks.
  • Explain Tests: Briefly describe the purpose of the test suite and what key scenarios are covered by the written tests.

Read the full file on GitHub · 114 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 114 lines · 34 tokens per session scan A 54b56ddb3c16

Subscribe to this mod's changes

Write-Tests is a cursor rule published in the GitHub repository TheSethRose/DevRules (25 stars, last pushed 1y ago), licensed MIT. It adds 34 tokens to every session and 1,361 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.