testingbddspockautomated-testsjbehave

Behavior Driven Development for java - what framework to use?


For the ongoing projects and for improving our development process we considered adopting TDD as development philosophy. While researching for best practices and how to "sell" the new approach to my colleagues/ developers I came across BDD and found it even more appropriate to what we would need and somehow to be next iteration of TDD. The problem is that up to now I tried only the tool developed by Dan North, JBehave and I cannot say that I am amazed.

The setup seems to me cumbersome and I couldn't find very appropriate documentation for it. On the other hand I tried also spock the groovy tool and up to now I kind of like it.

Q: are there any proper tools to be used for BDD?
Q: you would use instead spock and deal with the overhead of introducing another language?


Solution

  • 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:

    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.