In this post, we will discuss the most commonly used JBehave Annotations. Also, JBehave supports many annotations, we will discuss some most commonly used annotations here. The below 3 annotations are most commonly used in Step class methods.
To have a look at all the annotations supported, expand the package in jbehave.core package org.jbehave.core.annotations; in Maven dependencies as shown in the picture.
Update pom.xml with the dependency and update the project:
<dependency> <groupId>org.jbehave</groupId> <artifactId>jbehave-core</artifactId> <version>4.1</version> </dependency>
Once you have updated the project the Jbehave core dependency jar would be downloaded to your local repository from either central or remote repository depending on your setting.xml.
Each annotation holds a regex pattern as value, which is used to match the candidate steps to the textual story gherkin step. For example, the @Given annotation as shown in the below screen
Given numbers i and j
Candidate Step Method
@Given(“numbers i and j”)
Makes sure the story text matches the step annotation value. Also, the story editor throws a warning message if none of the step matches are found. Furthermore, JBehave requires that all candidate step classes to be instantiated before a story can be run. We will discuss more annotations later with examples.
JBehave Tutorials on this website can be found at:
For more details on the JBehave framework, visit the official JBehave website at: