---
type: method
slug: write-tests
title: "Write automated tests"
category: "Technology & Development"
subcategory: "Code quality"
level: starter
source: https://deepstoryresearch.com/method/write-tests
publisher: Deepstory Research
---

> **How to use this file:** attach it to ChatGPT, Claude, Gemini or Copilot (or paste the prompt section), replace every [PLACEHOLDER] with your details, and add any data or Deepstory evidence files the method needs.

## When to use this method
- Adding tests to new or legacy code.

## Prompt

# Write automated tests
Method by Deepstory Research: deepstoryresearch.com/method/write-tests

You are a test engineer. Follow the method below step by step. Goal: A test plan and test code covering happy paths, edge cases and failures.

## My inputs
- Code under test: [CODE_UNDER_TEST]  (example: paste)
- Test framework: [TEST_FRAMEWORK]  (example: Jest, Vitest, pytest)
- Behaviour spec: [BEHAVIOUR_SPEC]  (example: acceptance criteria)

Before you start: if any input above is still in [BRACKETS] or missing, ask me for it in one short numbered list and wait. Do not guess. If I attached files (data, briefs, Deepstory evidence files), treat them as the primary source.

## Steps to follow
1. List behaviours to test.
2. Design cases: happy, edge, error.
3. Write tests with clear names.
4. Mock external dependencies only where needed.
5. Explain how to run them.

## Deliver the output in this structure
- Test plan
- Test code
- Run instructions
- Coverage gaps

## Quality rules
- Tests must fail if the behaviour breaks, no tautologies.
- Label every number as FACT (with source and date), ESTIMATE (show the calculation) or ASSUMPTION.
- If a Deepstory evidence file is attached, use its figures as the reference values and cite its source references; tag claims that are not from it as [UNVERIFIED].
- End with: the 3 assumptions that matter most, what would change the answer, and the single best next step.

---
Deepstory methods are process guidance for AI tools. Review AI output before relying on it; legal, tax, medical and investment matters need a qualified professional.
