> Markdown version of [Behavior-Driven Development](https://vaadin.com/docs/next/flow/testing/end-to-end/bdd). Section index: [llms.txt](https://vaadin.com/docs/next/flow/llms.txt)

# Behavior-Driven Development

Behavior-Driven Development (BDD) is a development methodology based on test-driven development, where development starts from writing tests for the software-to-be. BDD involves using a *ubiquitous language* to communicate between business goals (i.e., the desired behavior) and tests to ensure that the software fulfills those goals.

The BDD process starts by collecting business requirements expressed as *user stories*, as is typical in agile methodologies. A user with a *role* requests a *feature* to gain a *benefit*.

Stories can be expressed as number of *scenarios* that describe different cases of the desired behavior. Such a scenario can be formalized with the following three phases:

<!-- vale Vaadin.FirstPerson = NO -->

- *Given* that I have calculator open,

- *When* I push calculator buttons,

- *Then* the display should show the result.

<!-- vale Vaadin.FirstPerson = YES -->

This kind of formalization is realized in the JBehave BDD framework for Java. The TestBench Demo includes a JBehave example, where the above scenario is written as the [following test class](https://github.com/vaadin/testbench-demo/blob/master/src/test/java/com/vaadin/testbenchexample/bdd/CalculatorSteps.java):

**CalculatorSteps.java**

```java
public class CalculatorSteps extends ChromeSteps {

    private KeypadElement calculator;

    @BeforeScenario
    public void setElements() {
        calculator = $(KeypadElement.class).first();
    }

    @When("I push $buttons")
    public void enter(String buttons) {
        calculator.calculate(buttons);
    }

    @Then("the display should show $result")
    public void displayShows(String result) {
        assertEquals(result, calculator.getDisplayValue());
    }
}
```

**ChromeSteps.java**

```java
// extend TestBench helper class for extra testing features
public class ChromeSteps extends AbstractBrowserDriverTestBase {

    // open webpage before test
    @BeforeScenario(order = 100)
    public void beforeScenario() {
        getDriver().get("https://" + IPAddress.findSiteLocalAddress() + ":8080");
    }

}
```

This demo employs the page object defined for the application UI, as described in [Creating Maintainable Tests using Page Objects](https://vaadin.com/docs/next/flow/testing/end-to-end/page-objects.md). Such scenarios are included in one or more stories, which need to be configured in a class extending `JupiterStories`.

In this example, TestBench is used to manage `WebDriver` and browser configuration. This is done in the [SimpleBDDCalculationIT.java](https://github.com/vaadin/testbench-demo/blob/master/src/test/java/com/vaadin/testbenchexample/bdd/SimpleBDDCalculationIT.java) class. It defines how story classes can be found dynamically by the class loader and how stories are reported.

For further information on this, see the JBehave website at <https://jbehave.org/>.

`5115165C-951D-436A-8F3F-C7BB2F83A054`
