0Pricing
Testing Mastery: JUnit, Mockito & Integration Tests · Lezione

Scenario Outline e tabelle di dati

Esegua un singolo scenario Gherkin con più set di dati usando Scenario Outline, tabelle Examples e tabelle di dati inline.

Scenario Outline e tabelle di dati è una lezione Testing Mastery: JUnit, Mockito & Integration Tests gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Testing Mastery: JUnit, Mockito & Integration Tests, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Testing Mastery: JUnit, Mockito & Integration Tests include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Repeating Scenarios

Often you want to run the same behavior with different inputs. Copy-pasting a scenario per case is wasteful. Gherkin's Scenario Outline parameterizes one scenario over many examples.

Placeholders with Angle Brackets

In a Scenario Outline, values are placeholders written in angle brackets, filled in from an Examples table.

Scenario Outline: add numbers
  Given I enter <a> and <b>
  When I add them
  Then the result is <sum>

The Examples Table

The Examples keyword introduces a table of rows. Each row runs the outline once with those values.

  Examples:
    | a | b | sum |
    | 2 | 3 | 5   |
    | 0 | 0 | 0   |
    | 5 | 7 | 12  |

How It Expands

Cucumber expands the outline into one concrete scenario per Examples row, substituting the placeholders. Three rows means three test runs.

Step Definition Receives Values

The step definition uses capture groups, and each expanded row supplies its values.

@Given("I enter {int} and {int}")
public void enter(int a, int b) {
  this.a = a; this.b = b;
}

Data Tables vs Outlines

An Examples table multiplies the scenario. A data table passes a structured argument to a single step.

Given the following users
  | name | role  |
  | Ada  | admin |
  | Bob  | guest |

Consuming a Data Table

The step receives the table, which you can convert into a list of maps or domain objects.

@Given("the following users")
public void users(DataTable table) {
  List<Map<String,String>> rows =
      table.asMaps();
}

Choosing the Right Tool

Use a Scenario Outline when the whole flow repeats with varied inputs. Use a data table when one step needs a collection of structured data.

Keeping Examples Readable

Name columns clearly and keep each Examples table focused. Large unfocused tables hide which behavior you are actually specifying.

Multiple Examples Blocks

You can have several Examples blocks under one outline, each with a tag or comment, to group happy-path and edge cases.

Why It Matters

Parameterized scenarios keep features concise and make boundary testing explicit and reviewable by non-developers.

Quick Check

What does each row of an Examples table produce?

Recap

You learned data-driven Gherkin:

  • Scenario Outline uses <placeholders> and an Examples table
  • Each row runs the scenario once
  • Data tables pass structured data to a single step
  • Pick outlines for repeated flows, data tables for collections

Domande Frequenti

La lezione «Scenario Outline e tabelle di dati» è gratuita?

Sì — il testo completo di «Scenario Outline e tabelle di dati» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Testing Mastery: JUnit, Mockito & Integration Tests, passa a CoddyKit PRO. Il corso Testing Mastery: JUnit, Mockito & Integration Tests include 4 lezioni in totale.

Cosa imparerò in «Scenario Outline e tabelle di dati»?

Esegua un singolo scenario Gherkin con più set di dati usando Scenario Outline, tabelle Examples e tabelle di dati inline. Eserciti Testing Mastery: JUnit, Mockito & Integration Tests con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Testing Mastery: JUnit, Mockito & Integration Tests?

Non è richiesta alcuna esperienza precedente. Testing Mastery: JUnit, Mockito & Integration Tests su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Scenario Outline e tabelle di dati»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Testing Mastery: JUnit, Mockito & Integration Tests?

Sì. Ogni lezione Testing Mastery: JUnit, Mockito & Integration Tests include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Introduzione al BDD
  2. Sintassi e funzionalità di Gherkin
  3. Implementazione delle definizioni dei passaggi
  4. Scenario Outline e tabelle di dati
← Torna a Testing Mastery: JUnit, Mockito & Integration Tests