jBehave plugin brings the following features:
- Step auto-completion
- Syntax highlighting
- Step hyperlink detection and link to corresponding Java step method
- Step validation, detecting both unimplemented steps and ambiguous steps
How to install and use the jBehave plugin:
- In Eclipse go to Help > Install New Software
- Add the new site location http://jbehave.org/reference/eclipse/updates/
- Select JBehave Eclipse feature and click next
- Take defaults for the rest of the prompts
- Restart Eclipse
Create a jBehave story
- right click on the package where you want to place you feature file
- select New->Other and the jBehave->New Story wizard
- in the Story dialog, name the story file name
- click finish
Example file:
Sample story
Narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development
Scenario: A scenario is a collection of executable steps of different type
Given step represents a precondition to an event
When step represents the occurrence of the event
Then step represents the outcome of the event
Create a class with the step automation from a scenario
- right click on the package you want to put the step automation
- select New->Class
- in the New Java Class enter the class name you have choosen
- click finish
For the example scenario file above we could genearte the following step implementations
package com.joe.steps;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.steps.Steps;
public class ExampleSteps extends Steps{
@Given("step represents a precondition to an event")
public void givenStepRepresentsTheOccurrenceOfTheEvent(){
//ToDo implementation
}
@When("step represents the occurrence of the event")
public void whenStepRepresentsTheOccurrenceOfTheEvent(){
//ToDo implementation
}
@Then("step represents the outcome of the event")
public void thenStepRepresentsTheOccurrenceOfTheEvent(){
//ToDo implementation
}
}
A simple way for running the tests is:
private static Embedder embedder = new Embedder();
private static List storyPaths = Arrays
.asList("[[Package]]/[StoryName].story");
public static void main(String[] args) {
embedder.candidateSteps().add(new ExampleSteps());
embedder.runStoriesAsPaths(storyPaths);
}