In Cucumber, what does a tag on a single Examples block select that a tag on the Scenario Outline cannot?
answer
- tags have a scope in Gherkin
- an Examples block can carry tags
- inheritance flows down and accumulates
- split one table into two blocks
- the block is the smallest taggable unit
basics
~20 sA tag above one Examples block applies only to the scenarios generated from that block's rows, so it can select a group of rows. A tag on the Scenario Outline applies to every row of every Examples block below it.
solid answer
~40 sGherkin lets an `Examples` block carry its own tag line, written directly above the `Examples:` keyword. Each scenario Cucumber generates from that block inherits the union of the feature's tags, any `Rule` tags, the `Scenario Outline`'s tags and that block's tags. Inheritance is **additive** and nothing is overridden. That union gives you row-group selection the outline-level tag cannot express, because a tag on the outline lands identically on every row. Split one wide `Examples` table into two blocks, tag only the slow or known-broken group, and a tag expression runs one group while skipping the other with the step text staying identical. You cannot get the same effect by templating a tag: a placeholder is never substituted into a tag name.
code
gherkin · 15 lines@billing
Scenario Outline: Invoice a <segment> district-heating meter
Given an account in segment "<segment>"
When the monthly billing run executes
Then the invoice status is "<status>"
Examples: settled segments
| segment | status |
| residential | issued |
| community | issued |
@wip
Examples: disputed segments
| segment | status |
| arbitrated | held |go deeper
Know that a tag line may sit above an Examples: block, not only above a scenario, and that it applies to the scenarios generated from that block's rows. Being able to point at the position in a feature file is enough here.
Explain the inheritance chain from feature to rule to outline to Examples block, that it accumulates rather than overrides, and why that scoping difference is the only way to select part of an outline.
Show the operational use: quarantining a handful of rows out of a nightly pack by splitting the table, rather than duplicating the outline or commenting rows out, and knowing the block is the smallest unit you can act on.
Own the selection scheme itself. Decide which tag vocabulary exists, whether quarantine lives in tags or in the pipeline configuration, and how a team avoids an outline shattering into a dozen one-row Examples blocks.
## Where the tags actually sit Gherkin allows a tag line above four things: a `Feature:`, a `Rule:`, a `Scenario:` or `Scenario Outline:`, and an `Examples:` block. That last position is the one candidates forget, and it is the only mechanism in the language for selecting *part* of an outline. An outline can carry several `Examples` blocks, each with its own optional name and its own optional tag line. When Cucumber expands the outline, every scenario generated from a block inherits the tags of that block **in addition to** everything inherited from above it. ## Inheritance is additive, never overriding | Tag written on | Applies to | Typical use | |---|---|---| | `Feature:` | Every scenario in the file, outline-generated or not | Whole-area selection | | `Rule:` | Every scenario under that rule | Grouping by business rule | | `Scenario Outline:` | Every row of every `Examples` block below it | The outline as a unit | | An `Examples:` block | Only the scenarios generated from that block's rows | Row-group selection | There is no precedence and nothing is shadowed: a scenario generated from a block tagged one way, under an outline tagged another way, in a feature tagged a third way, carries all three. A tag expression evaluated against that scenario sees the union. That union is exactly what makes the `Examples`-block tag useful. Tagging the outline itself cannot express "run these rows, skip those" — every row inherits it identically. Tagging one block can, because the two blocks now differ by one tag while the step text they expand into stays byte-identical. ## Buying selection by splitting the table The move is mechanical: 1. Take the one wide `Examples` table and decide which rows differ *operationally* — the slow ones, the ones that hit an external system, the ones that are known-broken. 2. Cut those rows into a second `Examples:` block under the same outline. Repeat the header row; each block has its own header. 3. Give the second block a name after the `Examples:` keyword so reports and diffs say why it exists. 4. Put a tag line above that block. 5. Select with a tag expression at run time; the untagged block keeps running as before. A district-heating billing team used exactly this on a tariff outline whose 23 rows included 4 that called a settlement service still being written three weeks before a contractor handover. Splitting those 4 into their own tagged `Examples` block took the outline out of the failing set of the 148-scenario nightly pack without deleting the rows, without duplicating the steps, and without leaving a commented-out block for the incoming contractor to puzzle over. ## What `Examples`-block tags cannot do - **They are not per-row.** The smallest taggable unit is the block. Excluding a single row means giving that row its own block, which is why outlines that need fine-grained selection drift towards several small tables instead of one wide one. - **They cannot be templated.** `@<segment>` is a literal tag name, because placeholders are substituted into step text, tables, doc strings and the outline's name — never into tags. - **They carry no built-in meaning.** Names such as the ones a team invents for smoke, nightly or work-in-progress groups are conventions your suite defines; the tool only matches them. Do not expect the runner to treat any team-invented tag specially. - **They do not change the step text.** Two blocks under one outline produce scenarios whose steps are indistinguishable except for the substituted values, so the split is invisible to the glue layer. ## Across the implementation family Cucumber-JVM and cucumber-js share the Gherkin parser, so both honour tags on an `Examples` block identically. SpecFlow/Reqnroll supports the same position in its own parser. Behave parses Gherkin itself; if you are relying on `Examples`-block tags there, confirm the behaviour against a throwaway feature before you build a selection scheme on it rather than assuming parity across the family. ## The interview angle The question separates candidates who have only *used* tags from those who understand where tags live in the Gherkin tree. A weak answer says "tags filter scenarios" and stops — which is true of every tag position and therefore answers nothing. A strong answer names the scope difference, states that inheritance is additive, and reaches immediately for the practical consequence: an outline is not an all-or-nothing unit, and quarantining a handful of rows does not require duplicating the outline or commenting rows out. The follow-up that usually comes next is whether you can tag a single row. Saying "no, the block is the unit, so I split the table" in one breath is the answer that lands, because it shows you have actually had to quarantine rows in a suite that other people depend on.
- The outline carries one tag and a single Examples block carries another. What runs under an expression that excludes the block's tag?Only the scenarios generated from the other block or blocks. Every generated scenario inherits the outline's tag, but only that one block's scenarios also carry the block tag, so the expression excludes exactly those rows and leaves the rest of the outline running normally.
- Can you tag one individual row of an Examples table?No. The smallest taggable unit is the `Examples` block, not the row. To exclude a single row you move it into its own `Examples` block, repeat the header, and tag that block. This is why outlines needing fine-grained selection tend to grow several small tables rather than one wide one.
- Does an Examples block's tag replace the tags it inherits from the outline?No. There is no precedence in Gherkin tag inheritance; the generated scenario carries the union of feature, rule, outline and block tags. That is what lets you keep a broad area tag on the outline while adding one narrow tag to a group of rows.
saying these in an interview costs you the question
- Thinks an Examples block tag overrides the outline's tags
- Believes you can tag an individual Examples row
- Writes a placeholder in a tag expecting per-row tagging
- Assumes Cucumber gives team-invented tag names built-in meaning
- Says tagging the outline can exclude some of its rows