Documentation versions (currently viewingVaadin 14)

You are viewing documentation for an older Vaadin version. View latest documentation

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 - the desired Behavior - and tests to ensure that the software fulfills those goals.

The BDD process starts by collection of 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 TestBenchTestCase {
    private WebDriver driver;
    private CalculatorPageObject calculator;

    public void setUpWebDriver() {
        driver = TestBench.createDriver(new FirefoxDriver());
        calculator = PageFactory.initElements(driver,

    public void tearDownWebDriver() {

    @Given("I have the calculator open")
    public void theCalculatorIsOpen() {;

    @When("I push $buttons")
    public void enter(String buttons) {

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

The demo employs the page object defined for the application UI, as described in Creating Maintainble Tests using Page Objects.

Such scenarios are included in one or more stories, which need to be configured in a class extending JUnitStory or JUnitStories. In the example, this is done in the class. It defines how story classes can be found dynamically by the class loader and how stories are reported.

For further documentation, please see JBehave website at