//given //when //then forever

public void shouldDoSomethingCool() throws Exception {


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! BTW. If you need to document some ‘exceptional’ behavior in your test somewhere there is the template for tests with exceptions.

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!

About these ads

25 Responses to //given //when //then forever

  1. 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. :-)

  2. szczepiq says:

    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!!!

  3. msuarz says:

    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

  4. Daniel Siwiec says:

    A nice debate on gwt style can be found here:

  5. padcom13 says:

    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.

  6. [...] in your tests, mockito has aliases in BDDMockito so that your actions can clearly follow the given/then/when [...]

  7. [...] is my preferred way of documenting ‘exceptional’ behavior. There you go, it is The Ultimate Test Template for ‘exceptional’ [...]

  8. [...] przez Pawła i sama idea jakoś nie bardzo mi podchodzi. Chyba pozostanę przy zwykłych testach z given, when, then. Jeśli ktoś natomiast BDD (Behavior Driven Development)  się interesuje to polecam przejrzeć [...]

  9. Hello! Quick question that’s completely off topic. Do you know how to make your site mobile friendly? My site looks weird when viewing from my iphone. I’m trying to find a template or plugin that might be able to resolve this
    problem. If you have any suggestions, please share.
    Many thanks!

  10. Nichol says:

    Yes! Finally someone writes about baltimore tours.

  11. cho thue nha says:

    After going over a number of the blog posts on your web page, I
    really appreciate your way of blogging. I saved it to my
    bookmark site list and will be checking back in the near future.
    Please check out my web site as well and tell me your opinion.

  12. W naszej ofercie znajdziecie Państwo profesjonalne folie wszelkiego typu
    i rodzaju. Polecamy zwłaszcza folię budowlaną, którą oferujemy w ogromnie atrakcyjnych cenach.

    Proponowana przez nas folia budowlana jest jedną z najlepszych na rynku, a co
    najważniejsze, wyróżnia ją naprawdę wyjątkowa cena.
    Dlatego promujemy ten produkt. Warto również dodać,
    że nasza folia budowlana ma gwarancję jakości, dzięki temu jest zakupem
    ewidentnie bardziej opłacalnym. Wyjątkowo duża odporność
    i skuteczność to jej najważniejsze zalety.

  13. Vivien says:

    I relish, cause I discovered just what I used to be looking for.
    You have ended my 4 day lengthy hunt! God Bless you man.
    Have a nice day. Bye

  14. Uta says:

    This design is incredible! You most certainly know
    how to keep a reader entertained. Between your wit and your videos, I was
    almost moved to start my own blog (well, almost…HaHa!) Wonderful job.
    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

  15. szukam zony says:

    Do you have a spam issue on this blog; I also am a blogger,
    and I was wanting to know your situation; we have developed some nice procedures and
    we are looking to exchange methods with others, why not shoot me an email if interested.

  16. I comment whenever I like a post on a website or if I have something to valuable to
    contribute to the conversation. Usually it is a result of the passion communicated
    in the article I read. And on this post //given //when //then
    forever | monkey island. I was actually moved enough to post a thought :-P I do have a couple of questions for you if you do not mind.
    Is it just me or do some of these responses appear like written by brain dead individuals?
    :-P And, if you are posting on other sites, I
    would like to keep up with you. Could you list every one of all your shared
    sites like your linkedin profile, Facebook page or twitter feed?

  17. sex oferty says:

    I usually do not drop a leave a response, but I read a few of the comments on //given //when //then forever | monkey island.
    I do have a couple of questions for you if it’s allright. Is it simply me or does it look like like some of the comments appear like they are left by brain dead individuals? :-P And, if you are posting on other social sites, I’d
    like to keep up with anything fresh you have to post. Could you post a list
    of all of all your public sites like your Facebook page, twitter feed, or linkedin profile?

  18. May I just say what a comfort to uncover someone who truly
    understands what they’re discussing over the internet. You actually understand how
    to bring a problem to light and make it important.
    More and more people ought to look at this
    and understand this side of the story. I was surprised you are not more popular because you certainly possess the gift.

  19. Hi, just wanted to tell you, I enjoyed this article. It was practical.

    Keep on posting!

  20. Sweet blog! I found it while searching on Yahoo News.
    Do you have any suggestions on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get
    there! Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 38 other followers

%d bloggers like this: