Given when then for coding agents: worth the ceremony?

Stefan-Iulian Tesoi · · 6 min read

An old loom in a dim workshop with patterned cloth curling off its front beam, a pattern set down precisely enough for a machine to weave it

Write given when then scenarios for a coding agent only where a scenario maps onto a test someone will run. The format forces a precondition, an action and an observable result, which is exactly what an agent needs. As prose that nothing executes, it adds ceremony without adding a check, and a command with its expected output does the same job.

The template is older than most of the tools that now parse it. Dan North and Chris Matts started writing acceptance criteria as scenarios in the early 2000s, and North's Introducing BDD, first printed in Better Software in March 2006, gives the shape: given some initial context, when an event occurs, then ensure some outcomes. Cucumber later turned that into Gherkin syntax a program can read. A team writing items for a coding agent inherits both halves, the discipline and the machinery, and usually needs only one of them.

What does given when then add to a criterion?

Three slots that cannot be left empty: the state before, the action taken, and a result someone can observe.

Most unverifiable acceptance criteria are missing one of the three, and the missing one is usually the precondition. "Exports work for large files" has no given, no when and a vague then. A person reading it supplies the rest from memory of the bug that prompted it. A coding agent supplies a plausible guess, implements the guess completely, and returns something that satisfies the sentence without fixing the problem.

Behaviour-driven development made the three slots a habit, and the habit is the valuable part. Writing "given an export of 120,000 rows" forces the author to pick a number, and the number is the decision the item was missing. That is the same test acceptance criteria an agent can verify have to pass: something to run, and an outcome to observe without judgement.

When does a scenario become ceremony?

When nothing runs it. A scenario pasted into a ticket, with no feature file and no step definitions behind it, is a checklist with capital letters.

The signs are easy to spot once you look for them:

A scenario nothing executes costs the same to review as a test and proves as much as a comment.

The cost is not the typing. It is the false confidence: a green build says nothing about scenarios that were never wired to anything, and a reviewer who sees Given/When/Then in an item tends to assume someone checked it.

Gherkin, a checklist or a command: which should you use?

Use the cheapest form that still names something a machine can run.

FormUse it whenWhat it costsWhat proves it
Cucumber scenarios in a .feature fileThe team already keeps BDD acceptance tests, or behaviour crosses several componentsStep definitions to write and maintainThe Cucumber run
Given/When/Then in the item text, no runnerThe precondition is the part people forgetNothing to maintain, and nothing runs itWhatever test the agent writes, which needs its own check
A command and its expected outputOne request, one script or one named test settles itA lineThe exit code and the output
A plain checklist lineCopy changes, documentation, removalsNothingA diff or a search

Most items on a typical backlog belong in the bottom two rows. The scenario form earns its place where several states interact, such as a trial that expires during checkout, because that is where an author skips a case and an agent quietly picks one.

One criterion written three ways

Take a banner that tells a workspace owner their trial has ended.

As prose: "Users with expired trials see an upgrade prompt on the billing page." It reads as finished. It does not say whether a trial ending today counts as expired, which is the case that breaks.

As a scenario:

Scenario: Trial ended yesterday
  Given a workspace whose trial ended yesterday
  When its owner opens /settings/billing
  Then the page shows "Your trial has ended"
  And the Upgrade button links to /checkout

As a command: pnpm test billing-banner passes, including a case for a trial that ended yesterday and one that ends today, and GET /api/workspaces/:id/billing for the first returns "trialExpired": true.

The scenario is the best of the three at making the author decide. The command is the best at being checked. The useful combination is to write the scenario to find the boundary, then put the command that tests it in the item, so the agent gets both the decision and the proof it has to produce.

Should the agent write the step definitions?

Yes, if someone else wrote the scenarios and the step definitions are reviewed as test code rather than glue.

Step definitions are where a scenario's meaning lives. Cucumber matches each line to code through a Cucumber Expression, and a step whose body asserts nothing still passes. An agent that writes the feature, the scenarios and the steps can make all three agree without any of them checking the requirement, which is the problem with tests written by the agent that wrote the code in a more formal costume.

Three habits keep it honest:

  1. Run the new scenarios against the code before the change. They should fail, and fail on the Then step.
  2. Read every Then step's definition. That is where an assertion either exists or does not.
  3. For UI steps, drive a real browser with Playwright, through playwright-bdd or plain Playwright tests, and assert on text, roles and URLs.

Laimonade asks the same of any check. A coding agent hands an item back with the commands it ran and their results, failures included, and the criteria are read against that evidence rather than the agent's summary of it. A criterion that names a command produces a row a reviewer can re-run. A Given/When/Then paragraph with no runner produces a claim that it was satisfied. The sprint workflow shows where that handover sits, and a backlog an agent can read covers the rest of what an item needs.

Frequently asked questions

Does Cucumber need to be installed for this to help?

No. Writing the precondition, action and result separately improves a criterion even when nothing parses it, because it forces the author to decide the boundary case. What you lose without a runner is proof: the scenario becomes a well-structured instruction, and the agent still needs a test or command that checks it.

Can one scenario cover several criteria?

It can, and it usually should not. A scenario that checks four outcomes fails as one unit, so the report says something broke without saying which criterion. Keep one observable outcome per scenario. A Scenario Outline with an Examples table covers one rule across several inputs without merging separate rules.

How do scenarios work for UI changes?

Through a browser driver such as Playwright, with each Then step asserting on visible text, an accessible role or a URL rather than on pixels. Layout and visual judgement stay with a person, so a UI item usually carries both: scenarios for behaviour, and one human check of how it looks at a stated width.