@Test
public void shouldDoSomethingCool() throws Exception {
//given
//when
//then
}
I like to call it the Ultimate Test Template. I’m so fond of those 3 little comments but surprisingly, I didn’t buy it at first. Micheal (it’s you, tapestry-maven-iPhone fan boy =), friend from ThoughtWorks showed me it a couple of years ago. Actually, he didn’t show it to me – I just overheard him coaching a young dev about it. That day I thought I didn’t need any hip comments because my tests were great anyway. It was foolish.
Don’t be a fool like me and start writing //given //when //then today. Life is too short for messing around – you want to get level 85 in software craftsmanship soon, right? Here’s the deal: use the template for 1 iteration and if you don’t like the results then I will give you your money back. Seriously, no matter what you think about it – buy it!
Lately, I’ve been selling //given //when //then quite relentlessly. I even try to sell it via Mockito api. (The link also shows how to install the template in Eclipse so don’t miss it!)
I tried to lobby for the Church of given-when-then in Krakow, Warsaw & Kiev. I heard rumors that Wroclaw develops a growing number of brothers and sisters in faith =)
I think I forgot to thank Dan North for given-when-then and Liz Keogh for the idea of BDD aliases in Mockito. There you go!
December 7, 2009 at 6:28 pm |
I used to do the same thing in JUnit. Then I created Spock (http://spockframework.org), which supports given/when/then natively and gives actual meaning to these terms.
December 7, 2009 at 8:00 pm |
You showed me spock at devoxx ‘08 as far as I remember =)
From the unit testing tools I’ve came across so far I must say spock has the coolest API. It is a total beauty. Well done!!!
December 8, 2009 at 4:59 am |
Hi Szczepan
I have my own mock framework (C#) http://fluentspec.com … it’s quite unusual and allows to write Given/When/Then in the test … nobody uses it but you might find something interesting about it
keep up the good stuff
cheers
mike
December 8, 2009 at 1:56 pm |
wow, fluentspec looks quite interesting – I’ll get back if I have any sensible feedback =)
December 23, 2009 at 6:45 pm |
A nice debate on gwt style can be found here:
http://blog.objectmentor.com/articles/2009/12/19/the-polyglot-tester
January 8, 2010 at 12:55 am |
I personaly prefer the arrange/act/assert schema but it boils down only to the names. The actual content of the sections is the same.
March 11, 2010 at 5:47 pm |
[...] in your tests, mockito has aliases in BDDMockito so that your actions can clearly follow the given/then/when [...]