Very simple step by step JBehave setup tutorial?

Viewed 51485

Though I have read many, but many articles on how to use JBehave, I can't get it to work. Here are the steps I went through so far:

  1. Created new Java Project
  2. Downloaded JBehave JAR file version 3.6.8 and added it to my build path libraries
  3. Created a package called com.wmi.tutorials.bdd.stack.specs under the test source folder in my workspace
  4. Added the JBehave JAR file to my Build path Library configuration
  5. Created a JBehave story in the above-mentioned package (StackBehaviourStories.story)
  6. Created a Java class in the above-mentioned package (StackBehaviourStory.java)
  7. Created a Java class in the above-mentioned package (StackBehaviourSteps.java)
  8. Imported the Given, Named, Then, When annotations in my Java class
  9. Written two different scenarios in my JBehave story file

And still, I can't get it to work/run! =(

The story file:

Narrative:
In order to learn to with JBehave using Eclipse
As a junior Java developer though senior in .Net and in BDD
I want to define the behaviour of a custom stack

Scenario: I push an item onto the stack
Given I have an empty stack
When  I push an item 'orange'
Then  I should count 1

Scenario: I pop from the stack
Given I have an empty stack
When  I push an item 'apple'
And   I pop the stack
Then  I should count 0

The story class

package com.wmi.tutorials.bdd.stack.specs

import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.junit.JUnitStory;

public class StackBehaviourStory extends JUnitStory {
    @Override 
    public Configuration configuration() { return new MostUsefulConfiguration(); }

    @Override
    public InjectableStepsFactory stepsFactory() {
        return new InstanceStepsFactory(configuration()
                                      , new StackBehaviourSteps());   
    }
}

The steps class

package com.wmi.tutorials.bdd.stack.specs

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.junit.Assert;

public class StackBehaviourSteps {
    @Given("I have an empty stack")
    public void givenIHaveAnEmptyStack() { stack = new CustomStack(); }

    @When("I push an item $item")
    public void whenIPushAnItem(@Named("item") String item) { stack.push(item); }

    @Then("I should count $expected")
    public void thenIShouldCount(@Named("expected") int expected) {
        int actual = stack.count();
        if (actual != expected) 
            throw new RuntimeException("expected:"+expected+";actual:"+actual);
    }
}

I'm currently using Eclipse Kepler (4.3) JEE with everything I need to use JUnit, Google App Engine, and yes, JBehave is installed correctly following the Eclipse JBehave installation tutorial.

I can't get it to work. So how can I make it work correctly using Eclipse, JBehave and JUnit?

4 Answers

i had updated the JunitStory to JunitStories and it worked

public class StackBehaviourStory extends JUnitStory ---> JunitStories

Related