Skip to content

Choosing a specification style

Chapter lab: Specification stylesch05-specification-styles.zip · 3 KB

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:

Terminal window
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch05-specification-styles.zip && unzip -q ch05-specification-styles.zip && rm ch05-specification-styles.zip

Open 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:

Terminal window
uv sync
Terminal window
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Keep the environment active in every terminal where you run lesson commands.

Terminal window
poetry install --no-root

Python 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/Then so 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

Read

Check your understanding

Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.

  1. Behavior-driven style is the best fit when…

    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.

  2. Data-driven (template) style shines when…

    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).

All terms in the glossary →