I love the Javascript BDD tool Jasmine, as it is highly flexible to define the stories. The stories in Jasmine can be structured in a way that the prerequisite stories are ran before the stories that depended on the previous ones. This makes the testing code highly re-usable, and readable.
Example of code reuse:
describe("parent story", function() {
var a = 1;
beforeEach(function(){
a++;
});
it("should equal to 2", function() {
expect(a).toBe(2);
});
describe("child story"), function(){
beforeEach(function(){
a++;
});
it("should equal to 3", function(){
expect(a).toBe(3);
});
});
});
I have done some research on using this concept in the Java world, and found the most popular BDD in Java is JBehave. However, it doesn't seem to be that flexible as Jasmine is in terms of re-using the testing code in the previous stories for the child stories. I couldn't see how it can pass in the reused variables into the child stories from the parent ones as the Jasmine example does.
JBehave has the GivenStories concept to run before the others, however I couldn't find how the state made in the GivenStories can be passed to the ones that depended on them.
Can JBehave do this work as nicely as Jasmine does? If not, is there another BDD framework in Java that can do the same thing?