My bad, i would rather go for jbehave

Hi reader,

Me again… In my last post I shared my experience with acceptance test tools. I invested time on looking for simple tool that does the job.

I must admit : I didn’t dig deep enough because if I did I wouldn’t have missed the java acceptance tests reference, JBehave to name it. To be honest I did find jbehave but at the time (about 10 weeks ago), the tool seemed to huge, to rich for me. I still felt young in acceptance testing, old enough to seek for another tool, but to young to provide a serious feedback on the topic. After trying other tools and facing their limitations I could tell what the ideal tool should look like for our teams.

Life can sometimes go hard on you. The minute I published my article I had a feedback from Mathilde who was a bit surprised with my choice. Her message was “Cool article but my guess is that you’ve never seen jbehave in action”. The doubt settled and I started studying jbehave just after. Here I am, sharing what I learnt.

Good thing is requirements don’t change :

integrates well with maven : check. I must admit it took me some time to figure out which goal to invoke. Because the tool is so highly configurable that you’re easily lost. But that’s the price for power …


has a simple yet structured syntax : check. You have a serious tool here. The grammar is written in EBNF understandable by the famous antlr.

Find interest points by example

@refs 12496


Given I provide a location
When I look for interest points
The system should return interestpoints arround that location

Scenario: Find interest points by example should succeed
Given I am a valid system user
And I provide the location 10 bd haussmann, 75009 paris
And I send application/x-www-form-urlencoded
And I receive <response-contenttype>
When I ask for interest points around that location
Then I should get a successfull response
And The response should include 21 interest points
And The response should include 5 restaurants
And The response should include 9 pubs
And The response should include 2 subway stations


leverages the classic given/when/then BDD paradigm : check.

cleanly separates behaviours definitions from their implementation : check. This feature is such a comfort as it allows every side to work at their rythm. The separation was made possible thanks to (roughly) 1) a solid grammar allowing the parser to easyly understand the structured story, 2) matching an implementation via Regex strategy and 3) running it. Below the implementation of the step “And The response should include 9 pubs” (shorter in groovy).

    @Then("The response should include $expectedPubsCount pubs")
    public void ensureExpectedPubsCount(@Named("expectedPubsCount") final int expectedPubsCount) {


        final int countMatches = CollectionUtils.countMatches(Arrays.asList(results), new Predicate() {

            public boolean evaluate(final Object object) {

                if (object == null)
                    return false;

                if (!(object instanceof InterestPoint))
                    return false;

                return InterestPointType.PUB.equals(((InterestPoint) object).getType());



        Assert.assertEquals(expectedPubsCount, countMatches);


allows advanced test techniques like parameterized tests, setup/teardown hooks, tags : check. JBehave allows you to parameterize your inputs, but also your expectations if suited for tabular form. You can use named params that allow you to get rid of the type/order method limitation. You can use any number of arguments of the same type, as soon as you name them.

has a fairly low memory footprint : check . Don’t get too greedy, it’s java after all :).

runs fairly fast : check. really happy with that one. You can configure more than one thread. Under the hood the java.util.concurrent.ExecutorService is used.

Besides those core features, jbehave has some extras that make it really far ahead of other ones :

i18n : “Given/When/Then/And” is english. If you’d rather use “Soit/Lorsque/Alors/Et” it’s up to you.

integration with major DI framework | support for groovy : Supports spring/guice/pico/weld. Moreover, instead of implementing your stories in java you can use groovy

meta information filtering : to me this is a killer feature. Say you define a @work_in_progress tag. You can instruct your release to fail if there still remain a @work_in_progress tag in the sories. You can bind tags to maven profiles launching somes tests only in that environment, etc.

hooks : before|after steps/scenarios/stories. Theses well defined extension points allow you to have more control on your excecution. Avoid overusing them as they tend to extend your build duration.

IDE integration : it seems to be an idea plugin but I don’t know if it offers completion on steps or cross-reference between stories. The eclipse plugin is not official, rather experimental :).

misc : very complete reference documentation with many examples provided and tutorial on github, responsive user list, well written.

Don’t bother looking elsewhere than on the reference documentation. They really did a great job.

I’m really happy Mathilde raised me doubts because now I’m able to come up with a serious tool and suggest it at work, especially for teams that don’t have a tool or have a complex and greedy one …

Steps to convince the business are :
– convince them to express their requirements with given/when/then
– then a little topic (basics) on your scm (update, commit)
– finally a good text editor with syntax highlight and preferrably completion (not that easy to find)

Well I hope this update on bdd tools sounds a little more appealing to you.




One thought on “My bad, i would rather go for jbehave

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s