Sub topic 7
Writing testable acceptance criteria
Acceptance criteria are the part of a feature spec that says how the team will know the feature is done. This chapter assumes you can already write a design intent and a rules section, as covered in earlier chapters. It also assumes you know the basic roles on a game team: design, engineering, art, and QA.
What acceptance criteria do
Rules describe how the feature works. Acceptance criteria describe what an observer can see when the feature works. An engineer uses them to know when to stop. QA uses them to build test cases. A designer uses them to decide whether to accept the work.
A criterion is testable when two people who read it will run the same check and reach the same verdict. If the verdict depends on taste, the criterion is not testable yet.
| Untestable | Testable |
|---|---|
| The dash feels responsive. | The dash starts within 2 frames of the button press. |
| The dash should not break in tight spaces. | Dashing into a wall ends the dash on the frame of contact. |
| Cooldown works properly. | After a dash, a second Dash press within the cooldown time starts no dash. |
| Damage interacts well with dashing. | When the player takes damage during a dash, the dash ends immediately. |
Notice that the testable versions name an action, a condition, and an observable result. Words like "properly", "well", and "responsive" hide the check inside the reader's head.
Where criteria come from
Each criterion should trace back to something earlier in the spec. Three sources cover most of them:
- Rules. Every numbered rule should have at least one scenario that proves it.
- Edge cases. Every listed edge case should have a scenario, because edge cases are where bugs concentrate.
- Design intent. Intent often cannot be checked directly in a test run, so translate it into a measurable proxy, such as input latency, or leave it for a playtest.
A useful check is to walk the rules and edge cases one by one and mark the scenario that covers each. Anything without a scenario is either untested or does not need to be in the spec.
The Given/When/Then format
Given/When/Then is a common format for scenarios. It splits a behavior into three parts:
- Given sets up the starting state.
- When names one action or event.
- Then states the observable result.
The format forces you to state the starting condition, which is what most informal descriptions leave out. The scenarios below belong to the Dash feature and use the Gherkin notation, which many test tools can read.
Feature: Dash
Scenario: Dash in the input direction
Given the player is on the ground and the dash is not on cooldown
When the player presses Dash while holding right
Then the player moves right at the dash speed for the dash duration
Scenario: Dash is blocked during cooldown
Given the player has dashed less than the cooldown time ago
When the player presses Dash
Then no dash starts
Scenario: Damage cancels a dash
Given the player is dashing
When the player takes damage
Then the dash ends immediatelyEach scenario checks one behavior. The names read like short sentences, so a reviewer can scan the list and see what the feature promises.
Refer to tuning values by name
The first scenario says "the dash speed" and "the dash duration" instead of "18 units per second" and "0.2 seconds". The numbers live in the tuning file:
# dash_tuning.yaml
dash:
speed: 18.0 # units per second
duration: 0.2 # seconds
cooldown: 0.8 # seconds
air_dashes_per_jump: 1This keeps the scenarios valid when a designer changes a number. If the scenario hard-coded 0.8 seconds and the cooldown became 0.6, the spec and the build would disagree even though nothing is broken. Name the value in the scenario, and let the test read the current value from the file.
Qualities of a good criterion
Check each scenario against this list.
- One behavior. If a scenario has two Then lines about unrelated results, split it.
- Observable. The result must be something a tester or an automated check can see: a position, a state, a sound, a UI element, a logged event. "The code handles it" is not observable.
- Specific about state. Say whether the player is on the ground, in the air, or carrying an object. Many bugs appear only in one state.
- Independent. A scenario should not depend on another scenario having run first.
- Free of implementation detail. Say "the dash ends", not "the DashState coroutine returns". Engineers may restructure the code without changing the behavior.
Covering negative and boundary cases
Teams tend to write scenarios for the happy path, where the feature works as intended. The negative path, where the feature must refuse to act, is equally part of the contract. The cooldown scenario above is a negative case: it proves that nothing happens.
Boundaries need their own scenarios. A cooldown of 0.8 seconds raises the question of what happens at exactly 0.8 seconds. Decide, then state it.
Feature: Dash cooldown boundary
Scenario: Dash is allowed when the cooldown has just ended
Given the player dashed exactly the cooldown time ago
When the player presses Dash
Then a dash starts
Scenario: Air dash limit is enforced
Given the player is in the air and has used all air dashes for this jump
When the player presses Dash
Then no dash starts
Scenario: Air dashes reset on landing
Given the player has used all air dashes for this jump
When the player lands on the ground
Then the player has the full number of air dashes againHere "exactly the cooldown time ago" settles the boundary in favor of allowing the dash. Without this scenario, one engineer might use "less than" and another "less than or equal to", and the difference would show up as an inconsistent feel.
Common errors
These are the mistakes that show up most often in acceptance criteria.
- Vague adjectives. Words such as "fast", "smooth", "intuitive", and "fair" cannot be checked. Replace each with a number, a frame count, or a defined comparison.
- Several actions in one When. "When the player dashes and takes damage" hides the order of events. Split it, or define the order.
- Hard-coded numbers that duplicate the tuning file. The spec drifts out of date. Use the value's name.
- Missing starting state. "When the player presses Dash, then a dash starts" fails if the player is in cooldown. The Given line prevents this.
- Describing the implementation. Criteria that name functions or classes lock the engineers into one design.
- No criterion for an edge case. If the spec lists "Dashing into a wall ends the dash immediately" as an edge case but has no scenario, nobody will test it.
When a scenario is not the right tool
Not every requirement fits Given/When/Then. Some feel-based goals need a playtest, and some performance goals need a measurement. You can still make them testable by stating the method and the pass line.
- Performance: "On the minimum-spec target device, frame time stays under 16.6 ms while three dashes are active." The method is a profiler capture.
- Feel: "In a playtest with at least five testers, at least four rate dash responsiveness 4 or higher on a 5-point scale." The method is a survey.
These are weaker than a scenario because they rely on people and devices, so list them separately and mark who runs them.
A short review routine
Before you send a spec for review, do this pass:
- List every numbered rule and mark the scenario that covers it.
- List every edge case and mark its scenario.
- For each scenario, read only the Given line and ask whether a tester could set up that state.
- Read each Then line and ask what a tester would look at to confirm it.
- Search for vague adjectives and hard-coded numbers.
Exercise
A spec says "Dashing should feel snappy, and the cooldown is 0.8 seconds." Rewrite this as two acceptance scenarios, one for the cooldown and one for snappiness, so that neither needs editing when the cooldown value changes.
Show answer
Cooldown: "Scenario: Dash is blocked during cooldown. Given the player has dashed less than the dash cooldown time ago. When the player presses Dash. Then no dash starts." The scenario names the cooldown instead of writing 0.8, so it stays valid when the tuning file changes. Snappiness: "Scenario: Dash starts promptly. Given the player is on the ground and the dash is not on cooldown. When the player presses Dash. Then the dash movement begins within 2 frames of the press." "Snappy" is replaced by a frame count that a tester can measure, for example with a frame-stepped recording.
Exercise
A scenario reads: "When the player presses Dash and gets hit, then everything works correctly." List three problems with it and fix them.
Show answer
First, it has no Given, so the starting state is unknown. Second, the When combines two events whose order is unclear. Third, "everything works correctly" is not observable. A fix: "Given the player is dashing. When the player takes damage. Then the dash ends immediately." If you also need the case where damage arrives before the dash, write a second scenario: "Given the player has taken damage this frame. When the player presses Dash. Then the result follows the rule for dashing during damage" and replace that last clause with the actual behavior your rules define.