Writing Simple JBehave Story : In this post, we will write a simple JBehave story in Eclipse. This post is suitable for beginners who want to kick start BDD using JBehave. If you haven’t installed JBehave Eclipse plugin I recommend looking at the post( Installing JBehave Eclipse Plugin )
Adding a new story in Eclipse
Once you have 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 below 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 ( POJO’s ). For example, in our case lets call it CalcSteps. For easy understanding see the diagram below for better understanding.
In addition, some steps might be common for lot of scenarios we can move them to CommonSteps. These can be reused across multiple stories and Scenarios.
Sample JBehave story below:
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.