Behavior Driven Development (BDD)

by:

Uncategorized

The scenarios are ideally phrased declaratively rather than imperatively – in the business language, with no reference to elements of the UI through which the interactions take place. This format is referred to as Gherkin language, which has a syntax similar to the above example. The term Gherkin is specific to such frameworks as : Cucumber, JBehave, Lettuce. Let’s take a more detailed look at Cucumber framework :

Cucumber requires the following dependencies providing its functionality :

  • cucumber-java : allows to create Cucumber Step Definitions (such as @Given, @When, @Then)
  • cucumber-junit : allows to run Cucumber test scenarios as JUnit tests

The code base of an example is shown below :

pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>JUnitCucumberExample</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.2.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.2.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

Previous Next

Leave a Reply

Your email address will not be published. Required fields are marked *