In this tutorial. we will write a simple JBehave story in Eclipse IDE. This post is suitable for beginners who want to kick start BDD using JBehave. If you haven’t installed the JBehave Eclipse plugin, we recommend looking at the post( Installing JBehave Eclipse Plugin )
Adding a new story in Eclipse
Once you have an Eclipse plugin successfully installed, you would get the new story in the New Wizard window. Click on it to create a new story as shown in the picture.
We can have multiple scenarios in a single file. But for simplicity sake, I will write 2 simple scenarios for a calculator addition and subtraction of two numbers lets say Calculator .story. Typically, each line in the story gherkin would be mapped to a java method in step classes (POJOs). For example, in our case, let’s call it CalcSteps. For easy understanding see the diagram below for better understanding.
Besides, some steps might be common for a lot of scenarios we can move them to CommonSteps. These can be reused across multiple stories and Scenarios.
Sample JBehave story
Scenario: ADD function Given numbers i and j When we add them Then verify the sum Scenario: SUBTRACT function Given numbers i and j When we subtract i from j Then verify the difference
In the next post, we write the step classes and connect the pieces and run the story from within the Eclipse IDE.
JBehave Tutorials on this website can be found at:
For more details on the JBehave framework, visit the official JBehave website at: