Choosing a specification style
Chapter lab: Specification styles
This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.
Download ch05-specification-styles.zip
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch05-specification-styles.zip && unzip -q ch05-specification-styles.zip && rm ch05-specification-styles.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch05-specification-styles.zip -OutFile ch05-specification-styles.zip; Expand-Archive ch05-specification-styles.zip -DestinationPath .; Remove-Item ch05-specification-styles.zipOpen the folder in VS Code with code rfe-ch05-specification-styles (or File → Open Folder…) and accept the recommended RobotCode and Python extensions. Then set it up:
uv syncpython3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtpython -m venv .venv.venv\Scripts\Activate.ps1pip install -r requirements.txtKeep the environment active in every terminal where you run lesson commands.
poetry install --no-rootPython 3.13 or newer is required; uv installs it when it is missing.
Open in browserNo setup? Try the lab right here: its files, an editor and a terminal, running in your browser.
What's inside
Directoryrfe-ch05-specification-styles/
Directory.vscode/
- extensions.json
Directorychecks/
- prices.robot
- .gitignore
- .python-version
- LAB.md
- pyproject.toml
- README.md
- requirements.txt
- uv.lock
You have now written all three specification styles. Each suits a different job:
- Keyword-driven — the default. Tests are sequences of keyword calls. Use it for most work; it is the most flexible.
- Behavior-driven — keyword calls prefixed with
Given/When/Thenso a test reads as a sentence. Use it when non-engineers read or write the tests, or when the behavior is the specification. - Data-driven — a template run once per data row. Use it when one action is checked against many input/expected pairs; it removes repetition.
These are not exclusive. A suite can be mostly keyword-driven with one templated data table, and a behavior-driven test can call templated keywords underneath. Choose the style that makes each test easiest to read and to change.
Answer the recall check below, then continue to structure and execution control.
Read how to choose between the three styles
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
Behavior-driven style is the best fit when…
Behavior-driven style expresses tests as readable Given/When/Then sentences; data-driven suits many-rows, keyword-driven is the default.
Show the answer
Answer: tests should read as Given/When/Then sentences for non-engineers — Behavior-driven style expresses tests as readable Given/When/Then sentences; data-driven suits many-rows, keyword-driven is the default.
Data-driven (template) style shines when…
Templates collapse many near-identical tests (one action, many data rows) into a compact table.
Show the answer
Answer: one action is checked against many input/expected pairs — Templates collapse many near-identical tests (one action, many data rows) into a compact table.
Key terms
- specification stylesconcept
- Keyword-driven (default), behavior-driven (Given/When/Then), data-driven (templates).