Does JBehave work like Jasmine?

I like the Jasmine Jasmine BDD tool, as it is very flexible to define stories. Jasmine stories can be structured so that preliminary stories run before stories that are dependent on previous ones. This makes the testing code very readable and readable.

Code Reuse Example:

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 did some research on using this concept in the Java world and found that the most popular BDD in Java is JBehave. However, it does not seem to be as flexible as Jasmine in terms of reusing the testing code in previous stories for children's stories. I could not figure out how this could pass reusable variables to child stories from the parent, like the Jasmine example.

JBehave has a Concept Concept that runs before others, however I could not find how the state created in DataStories can be conveyed to those that depend on them.

Can JBehave do this job as well as Jasmine? If not, is there another BDD environment in Java that can do the same?

+4
source share
1 answer

JBehave and Jasmine are not alike. Jasmine is much more like rspec. JBehave and Cucumber (another BDD model, more popular, I think) are more alike than Jasmine or rspec.

Although JBehave does not have nested Jasmine contexts, it certainly can pass state between steps. Take a look at http://jbehave.org/ : state is passed in the instance variables of the Steps class. Cucumber works similarly, although the Ruby version, at least (I'm not familiar with Java Cucumber), is more flexible, in this state you can pass from any step to any other step as an instance variable of Cucumber World.

Be careful though: in all of these frameworks, resource sharing is designed so that you can create tests in several steps, and not so that the tests depend on each other. Tests can share code, but whether one test should pass or not run, should be completely independent of whether another test passes or does not pass. Once you say something, you are no longer in the setup, you are testing, and you should not reuse your state for another test.

+1
source

All Articles