tags:

views:

2602

answers:

4

What's the best BDD framework to use with Java? Why? What are the pros and cons of each framework?

I've found couple of them here, but I'm not sure which one to choose.

Does it make sense to use a BDD framework if I already use a mocking library (e.g. Mockito)?

+2  A: 

I originally did my BDD with plain jUnit but I've been looking at JDave lately because it's almost 1:1 to what I was doing with jUnit. It also runs on top of jUnit so it already works on Eclipse and is also easy to configure to work on continuous integration systems such as Hudson. Can't really compare it with others but my experiences with JDave have been good so far.

Oh and it's never a stupid idea to use mocks! They're not tied to TDD/BDD specifically, their purpose is to ease the burden of testing in general.

Esko
+1  A: 

Wow, I see the topic is hot, lot of good answers...

Irony aside, I recently discovered BDD and found the concept interesting. Hey, it forces to write both tests... and specifications! As surprising as it might seem, the latter can be also missing in some projects... Or just lacking the precision that BDD forces to introduce.

The Behavior Driven Development article summarizes the concept and links to some good articles (like the one written by Andrew Glover). Moreover, to the topic of this thread, it gives a rather comprehensive (I suppose) listing of BDD frameworks, a good number of them being for Java.
It doesn't solve the problem of choosing the framework but at least it will ease the search...

Since BDD relies heavily on readability of test code, I suppose a good criterion of choice is to look at the quick tours/tutorial and see which one seems the more fitting your style. Other criteria could be the fact a framework leverage tools you are familiar with (unit test, mocking), usage with IDE, and so on.

PhiLho
+1  A: 

My team have been using JBehave for some time. It uses plain text files to store specifications. Every step (Given, When, Then) is then executed by a certain method which can extract parameters from the step. Scenarios can be indented and well formatted which helps a lot if clients want to verify them.

There are some problems, too. We have switched to Java 6. Sometimes some scenario steps are ignored during execution. It may cause a lot of trouble figuring out where's the bug.

Boris Pavlović
@Boris Could your issue be that PENDING steps count as pass (the default behavior) instead of fail? If that's your issue, you can configure the PendingErrorStrategy:http://jarvana.com/jarvana/view/org/jbehave/jbehave-core/2.2.1/jbehave-core-2.2.1-javadoc.jar!/org/jbehave/scenario/errors/PendingErrorStrategy.html
JeffH
@JeffH many thanks
Boris Pavlović
+3  A: 

What's the best BDD framework to use with Java? Why? What are the pros and cons of each framework?

Here is an interesting link about Concordion vs. Cucumber and Java based Acceptance Testing

I've found couple of them here, but I'm not sure which one to choose.

Really, look at the one mentioned above.

Does it make sense to use a BDD framework if I already use a mocking library (e.g. Mockito)?

Short answer: yes, definitely. Actually, acceptance testing using a BDD framework and unit testing in isolation using mock objects are so different that I don't really get the question. Acceptance testing is black box testing, tests are used to verify that a business feature is working and are ideally written by business analyst. Unit tests in isolation using mocks is white box testing, tests are used to verify that a unit is working and are written by developers. Both are useful buty they have totally different purposes. In other words, using Mockito doesn't replace a BDD framework at all and the inverse is also true.

Pascal Thivent