Documentation

Documentation versions (currently viewingVaadin 23)
New Acceleration Kits: Kubernetes Kit and Azure Cloud Kit. Read the blog post.

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:

  • Given that I have calculator open,

  • When I push calculator buttons,

  • Then the display should show the result.

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:

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());
    }
}

This demo employs the page object defined for the application UI, as described in Creating Maintainable Tests using Page Objects. 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 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