Java BDD

I notice there’s another Behavior Driven Development framework for Java called Instinct (via). I have commented on BDD before.

Here’s an example test:


import static com.googlecode.instinct.expect.Expect.expect;
import com.googlecode.instinct.marker.annotate.BeforeSpecification;
import com.googlecode.instinct.marker.annotate.Context;
import com.googlecode.instinct.marker.annotate.Specification;

public final class AnEmptyStack {
    private Stack<Object> stack;

    @BeforeSpecification
    void setUp() {
        stack = new StackImpl<Object>();
    }

    @Specification
    void mustBeEmpty() {
        expect.that(stack.isEmpty()).equalTo(true);
    }
}
 

Yeah, that’s… great. What would it look like in a doctest?


>>> Stack<Object> stack = new StackImpl<Object>();
>>> stack.isEmpty()
true
 

Of course you have to invent a REPL for Java, but I’m sure that’s not very hard.

What does all that class infrastructure, setUp, mustBeEmpty and the weird DSLish stuff give you? Beats me. Doctest started in Python but now also exists in Ruby and Javascript. Someone needs to port the concept to Java too. People ported SUnit all over the place, so there’s no reason a good idea can’t spread. I can’t help feel that BDD is a case of a bad idea spreading; the motivations for BDD are fine (a change in developer testing workflow), but the technique they use to try to reach the desired workflow is totally bizarre.