Learn Everything

Paths/Codex Engineer/Testing with Codex / Writing Tests

Guided Taskbeginnerubuntu:24.04Ask AI

Ask for the Test First

A test written before the implementation is a specification you can read. Write the brief that asks for one.

Validator

⏱ 0:00

IDLE — checks run live as you type commands; submit when done

01Requirements

live checks
  • Directory ~/codex/tests exists○
  • File ~/codex/tests/brief.md exists○
  • The brief states the behaviour and the case to cover○
  • The brief states the assertion and what must not be asserted○

02Walkthrough

4 steps
  1. 01

    Create the tests directory

    The briefs for generated tests live with the repository.

    mkdir -p ~/codex/tests
  2. 02

    Write the behaviour brief

    Describe the behaviour in one sentence and name the case. The agent writes the test from the behaviour, not from the code it will later change.

    echo '# Test brief\n\n## The behaviour\n\nThe cursor encoder round trips: encode a position, decode it, get the same position back.\n\n## The case to cover\n\nA position with a non-zero offset, and a position at the end of the list.' > ~/codex/tests/brief.md
  3. 03

    Write the assertion rules

    The test must fail before the implementation exists, and it must assert the behaviour rather than the shape of the code.

    echo '\n## The rules\n\n- write the test before the implementation, and run it to watch it fail\n- assert the behaviour, never the internal implementation\n- one behaviour per test, so a failure names the problem\n- no snapshot of the whole function' >> ~/codex/tests/brief.md
  4. 04

    Verify and submit

    cat the brief, then submit for validation.

    cat ~/codex/tests/brief.md

03Stuck?

0 of 3 revealed

Take a hint without losing the lab — each one points at the thing to look at, not at the answer.

04AI Tutor

guides, never solves

Tell me what you're stuck on — I'll nudge, not solve. Which requirement are you looking at?

04Notebook

saved locally in this browser

learner@lab — ubuntu:24.04

↑/↓ recalls commands · Ctrl+Enter submits · type help for the command list