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:
com.wmi.tutorials.bdd.stack.specs
under the test source folder in my workspaceAnd 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?
Following step by step closely the jbehave Getting Started
tutorial, the Run story section says: [...] the ICanToggleACell.java class will allow itself to run as a JUnit test.
This means that the JUnit library is required in your Build path.
Using Eclipse:
ICanToggleACell.java
class, right-click it, then Run As, and click on JUnit TestSo this is the same here as for the above-example code. The StackBehaviourStory.java
class should let itself run as a JUnit test after you add the proper library to the Java build path.