Automation Testing

How to get Started using the Eclipse jBehave Plugin

By Test Guild
  • Share:
Join the Guild for FREE

Do you suffer from SpecFlow Envy?

If you have worked in a .NET environment using BDD with the BDD tool Specflow and then switched to a project that used Java, you might be suffering from SpecFlow envy. Specflows integration with Visual Studio is awesome, and it does a lot of things behind the scenes automatically for you.

When you start working in a BDD Java environment you will most likely miss some of Specflow's features.

If you are using jBehave –envy no more – there's a jBehave plugin available for Eclipse that helps get some of the Specflow functionality that you crave.


JBehave Plugin Features

By integrating the jBehave plug-in with Eclipse, you get the following features:

  • Step auto-completion
  • Syntax highlighting
  • Step hyperlink detection and link to corresponding Java step method (Ctrl+click)
  • Step validation, detecting both unimplemented steps and ambiguous steps

You can also go into the jBehave preferences in Eclipse and change:

  • Syntax color themes
  • Story language
  • Console logger levels


For the following example to work, I'll assume you already have all the jBehave jar files added to your Libraries area in the project Java Build Path.


How to install the Eclipse JBehave Plug-In

  1. In Eclipse, go to Help>Install New Software
  2. Click the Add button
  3. In the Add Repository dialog, enter:
    1. Name: JBehave
    2. Location: jBehave – http://jbehave.org/reference/eclipse/updates/
  4. Under the Available Software dialog, click on the jBehave option


  1. Click Next>
  2. Take defaults for the rest of the prompts
  3. Restart Eclipse

JBehave New Story Wizard

To verify that the plugin installed, when you right click on a project and select New>Other you should now have an option for a jBehave>New Story wizard.


Quick Example – jBehave Plugin in Action

The best way to get started with the jbehave plugin is to create a quick, simple, project to become familiar with how it works. So let's create a new project in Eclipse and take a look.

Create a new project

  1. In Eclipse, Create a New>Java Project
  2. In the New Java Project dialog, enter the project name jBehavePlugIn
  3. Click Finish
  4. Create two new Packages named:
    1. com.joe.steps
    2. com.joe.features * jBehave calls features—stories. To stay consistent with Gerkin and Cucumber standards we will instead use the term features.


Create a jBehave story

  1. Right click on the com.joe.features package and select New>Other and the JBehave>New story wizard
  2. In the Story dialog, name the story File name: debugPlugIn.feature


  1. Click Finish
  2. You should now have a debugPlugIn.feature file that looks like this in the IDE:


Notice how all the Given, When and Then steps have a yellow triangle with an exclamation point next to them. This shows that there are currently no steps in the project that match the Given, When or Then statements. Clicking on one of the triangles would show a No step is matching message:


If you clicked on one of the Scenario statements using Ctrl+Click, you would get the following message:


Create a Steps Class

Let's create a step class and add a step definition for the first Given statement.

  • Right click on the com.joe.steps package and select New>Class
  • In the New Java Class enter the Name: debugPluginSteps
  • Click Finish
  • Open the debugPluginSteps.java class and add the following import statements:
    • import org.jbehave.core.annotations.Given;
    • import org.jbehave.core.annotations.Then;
    • import org.jbehave.core.annotations.When;
  • Create the following Given method using the first Given step
    step represents a precondition to an event that we have in our debugPlugIn.feature file:
@Given("step represents a precondition to an event")
public void debugStepGivenTest(){

}


Save the project and return to the debugPlugin.feature file. Notice how the first Given step represents a precondition to an event no longer has a yellow triangle next to it. Hold the control key down on your keyboard and click on the Given step represents line, and – check it out – it takes you directly to its corresponding Java step!

jBehave Plugin Wrap-up

That's it. It may not seem like much, but this will be a huge time saver; especially when you start having lots of features and lots of steps. It's also great to get a visual look at a feature file and be able to automatically see which scenarios still need step definition code defined.

  1. We need more tutorial like this which shows
    -relation between schearios and steps.
    – writing complex @Given, @when and @Then

  2. Very good for the beginner of JBehave. But why the executing class is not included?
    Thanks.

  3. Hi there,

    This is very nice article, Please also let us know that what jars files are needed to add, because i ab only able to find out one .jar file (jbehave-core-3.6.8.jar), Also do mention the dependencies needs to add to a maven project.

    Also provide the code for running class.

    Thanks!

  4. The imports don’t work. There is a red wavy line under “org.jbehave.core” part of the import. Has anything changed?

  5. Thanks for your valuable information in this tutorial. If you could not able to post you please send the code to my E-mail id. This will be a great help for me. Could you please develop a JBehave _Selenium script for login functionality and script for running with JUnit.

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Leveraging AI and Playwright for Test Case Generation

Posted on 11/22/2024

Two BIG trends the past few years in the software testing space been ...

Symbolic AI vs. Gen AI: The Dynamic Duo in Test Automation

Posted on 09/23/2024

You've probably been having conversations lately about whether to use AI for testing. ...

8 Special Ops Principles for Automation Testing

Posted on 08/01/2024

I recently had a conversation, with Alex “ZAP” Chernyak about his journey to ...

Sponsor The Industry-Standard E2E Automation Testing Annual Online Event (Limited Spots Left) - Reach Out Now >>