One of the latest hypes is BDD. In Scala there are quite a few BDD libraries available. E.g. Specs.
I was curious to see if there was any library available for Java as well and I found a few:
My personal favourite based on the examples would be EasyB which allows you to write stories with a combination of human understandable language and groovy's expressiveness to test the actual behaviour.
I will shortly try to explain what BDD tries to offer next to good ol' plain interfaces and what some shortcomings of normal interfaces are.
Let us start with discussing following interface:
So this interface should form 'the contract' for the concrete implementation. But what would prevent me from writing following implementation which does nothing from the behaviour we intended.
And for all we know the method could be invoked like addRecipient("Robby Pelssers") which is not exactly a valid email address.
So if we were to add behavioural conditions to our interface, we might be better off. Let us take a look at a revamped version of our interface. The syntax will of course depend on the BDD library, but the idea should be clear.
No comments:
Post a Comment