Behavior Driven Development for java – what framework to use? [closed]

Behavior Driven Development is just a technique that can be used without any tools. You can just write tests in BDD style – e.g. start test methods with should and introduce some separate feature with this method. When and then sections can be replaced with just comments, e.g.

@Test
public void should_do_something() {
    // given
    Something something = getSomething();

    // when
    something.doSomething();
    // then 
    assertSomething();

    // when
    something.doSomethingElse();
    // then 
    assertSomethingElse();
}

My opinion on the mentioned frameworks:

  • The problem with JBehave is that tests look like a complex spaceship. On the other hand it has pretty output for your specifications.

  • spock is really cool. Compact syntax, pretty output, a lot of features, written with the powerful groovy language, which means the possibility of usage in conjunction with geb. BUT it is groovy and it can be very important for someone.

  • scalatest (written with scala) and easyb (written with groovy) both have the same disadvantage as spock. The “… should …” and “Given…Then” notation. Specifications are in .story files, and the step implementations are in Java classes. This approach work very well as a collaboration and communication tool to define the specs, but would usually be too much overhead for low-level coding.

I also think that the most successful BDD frameworks for Java are those that are not written in Java, since the Java language has no such flexibility for DSL (Domain Specific Language) creation that Groovy or Scala has.

Leave a Comment