A minimal jbehave maven project
I'm dipping my toes in BDD and learning the jbehave framework. I found it surprisingly difficult to find a simple, self-contained example to use as a starting point. I wanted a maven project that depended only on junit and jbehave.
Here's my minimal jbehave maven project; I hope it helps someone else get up and running quickly. Thanks to David Daedalus and Andreas Ebbert-Karroum, whose code I borrowed, trimmed, and mashed together.
Project Directory Structure
You need 4 files: pom.xml, AnnotatedSteps.java, RunJBehaveStoriesAsAJUnitTest.java, and Math.story in the following directories:
src/test/java/...package.../AnnotatedSteps.java src/test/java/...package.../RunJBehaveStoriesAsAJUnitTest.java src/test/resources/Math.story src/pom.xml
The filename Math.story is only significant in that RunJBehaveStoriesAsAJUnitTest's storyPaths method specifically looks for it. You could instead match patterns (like David Daedalus does) using one of StoryFinder's findPaths methods.
Source code
Edit: I didn't love the way the source was formatted here. Instead, I've created a repo over at bitbucket to house it.
The most interesting part is the scenario told in Math.story, an example written in the "given...when...then..." structure:
Scenario: 1 + 1 = 2 Given a variable x with value 1 When I add 1 to x Then x should be equal to 2
This is what appeals to me about BDD: examples drive feature development. These examples later serve as automated regression tests. You're also creating living technical documentation with these examples; it's never out of date because it's executable.
Running
run on the command line with mvn clean test
...snip... (BeforeStories) Running story Math.story (Math.story) Scenario: 1 + 1 = 2 Given a variable x with value 1 When I add 1 to x Then x should be equal to 2 (AfterStories) ...snip...











