Retext
CodeiumCopilotTesting

Codeium Testing Prompt Template

You get runnable tests that cover the normal case, the edges and the failure paths, written in your framework and naming style. This version is set up for Codeium: select the relevant code before asking, and name the files and functions involved. Below you'll find the prompt, how to run it in Codeium, a worked example and answers to common questions.

Installs as a snippet — type ;writetests to paste this prompt anywhere on your Mac.
Prompt Template
Write tests for the code below.

## Code under test
Language and test framework: [e.g. TypeScript with Vitest]
[paste the function, class or module]

## What it should do
[describe the intended behavior, including rules that are not obvious from the code]

## Coverage I want
- The main happy path
- Edge cases: [e.g. empty input, very large values, unicode, null]
- Error cases: [what should throw or return an error]

## Instructions
- Use only the test framework named above, no extra libraries.
- One behavior per test, with a test name that says what is expected.
- Use realistic input values, not "foo" and "bar".
- If the code has a bug that a test would expose, write the test anyway and tell me it will fail.

## Output format
1. The full test file, ready to run
2. A short list of anything you chose not to test and why

Context
- Files involved: [list the files, or reference them in the chat]
- How I build and test: [e.g. npm test]

How to use this prompt

  1. 1

    Open Codeium

    Open Codeium's chat in your editor and paste the prompt.

  2. 2

    Give it context

    Select the relevant code before asking, and name the files and functions involved.

  3. 3

    Review and iterate

    Ask follow-ups in the same chat and apply changes after reading them.

Working in Codeium

  • •Autocomplete and chat do different jobs: autocomplete finishes code you are typing; chat follows instructions like this prompt.
  • •Keep each request to one function or one problem for focused answers.
  • •Paste the exact error text when debugging rather than paraphrasing it.

Worked example

What you give it

Language and framework: JavaScript with Vitest

export function slugify(text) {
  return text.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
}

What it should do: turn a title into a URL slug with single hyphens and no leading or trailing hyphens.
Edge cases: punctuation, extra spaces, symbols only.

What a good answer looks like (shortened)

import { describe, it, expect } from "vitest";
import { slugify } from "./slugify";

describe("slugify", () => {
  it("lowercases and joins words with hyphens", () => {
    expect(slugify("Hello World")).toBe("hello-world");
  });

  it("collapses punctuation runs into one hyphen", () => {
    expect(slugify("Rock & Roll!!")).toBe("rock-roll");
  });

  it("strips leading and trailing hyphens", () => {
    expect(slugify("  --Draft--  ")).toBe("draft");
  });

  it("returns an empty string for symbols only", () => {
    expect(slugify("!!!")).toBe("");
  });
});

Not tested: accented letters are dropped, so "Café" becomes "caf". Confirm whether that is acceptable before I add a test.

Tips for better results

  • •The "What it should do" section matters more than the code. Rules like "discounts never stack" are invisible in the source and are exactly what tests should check.
  • •List your edge cases explicitly under Coverage I want. The AI tends to stop at the happy path unless you name empty, null and boundary values.
  • •Keep each request to one function or one problem for focused answers.
  • •Avoid this: Not naming the test framework, then getting a file that imports a library your project does not use.

Get the free prompt pack

Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.

Variations

Integration tests

Replace Coverage I want with: Test [module] together with a real [database or HTTP layer], and include setup and teardown.

Table-driven

Add this line to Instructions: Use a parameterized test (e.g. it.each or pytest.mark.parametrize) for cases that share the same shape.

Existing test file

Add this section: ## Current tests [paste them] and only add tests for behavior these do not already cover.

Save it as a Retext snippet

Retext is a free text expander for Mac. Save this prompt once, then type ;writetests in any app (ChatGPT, Claude, your editor, a browser tab) and the full prompt is pasted in.

  1. Click Add to Retext. The prompt installs as a snippet with the trigger ;writetests.
  2. Change the trigger in Retext if you prefer a different one.
  3. Type the trigger wherever you want the prompt, then fill in the brackets.

Frequently asked questions

Can AI-written tests be trusted?

Treat them like tests from a new teammate. Run them, read the assertions, and check that each one would fail if the behavior broke. A test that can never fail is worse than no test.

What context helps most?

The code you selected, the language and framework, and what you expected to happen. The prompt has a slot for each.

How many tests should I ask for?

Ask for coverage of behaviors, not a number. One test per rule and per important edge case is usually enough, and it keeps the file readable.

How do I reuse this prompt without copying it every time?

Click Add to Retext to save it as a snippet. Then type ;writetests in any Mac app, including your AI tool, and the full prompt is pasted in.

Related Templates

Get the free prompt pack

Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.