//given //when //then forever

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

50 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
    cheers
    mike

  4. Daniel Siwiec says:

    A nice debate on gwt style can be found here:
    http://blog.objectmentor.com/articles/2009/12/19/the-polyglot-tester

  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

  21. It’s very simple to find out any matter on net as compared to books, as I found this post at this site.

  22. I’m not that much of a internet reader to be
    honest but your sites really nice, keep it up!
    I’ll go ahead and bookmark your website to come back later on.
    Cheers

  23. Warsaw Shore: Ekipa camaro z Warszawy , process typu inescapable
    fact reveal
    bazujący kod nas formacie Ekipa camaro Nj-new jersey, produkowany as i emitowany
    poprzez MTV Polska. Jego premiera odbyła się
    w listopada 2013 roku instances Warsaw Shore 2 sezon odcinek 5 online, ekipa z warszawy
    sezon 2 odcinek 5 godzinie 5: 00. Od 22 Maja 2014 roku process jest emitowany również w Danii,

    Szwecji, Niemczech, Szwajcarii, Finlandii, Belgii, Holandii,
    Norwegii oraz Warsaw Shore 2 sezon odcinek 5 online, ekipa z warszawy sezon 2 odcinek 5rejonach Flandrii.
    Warsaw Shore osiągnął najwyższe wyniki oglądalności MTV Polska
    od czasu powstania stacji. eight lutego 2014 roku MTV Polska ogłosiła, że wiosną Warsaw Shore 2 sezon odcinek 5 online,
    ekipa z warszawy sezon 2 odcinek 52014 roku wyemitowana zostanie druga podria ser programu.
    Zaplanowano również
    wybranie nowych uczestników programu
    warsaw shore online, warsaw shore sezon 2
    online, warsaw shore sezon 2 odcinek 5 online, warsaw shore odcinek 5 online, warsaw shore livestream, warsaw shore download, warsaw shore
    poberz, ekipa z warszawy online, ekipa z warszawy sezon 2 online,
    ekipa z warszawy sezon 2 odcinek 5 online, ekipa z warszawy odcinek 5 online, warsaw shore oscinek 5 pobierz, warsaw shore odcinek 5 download

  24. Nadzwyczaj odlotowy post, interesujące zapisy zalecam wszystkim literaturę

  25. paintball says:

    Treść pokrewna każdemu, polecam literaturę

  26. An impressive share! I have just forwarded this onto a friend who was
    conducting a little homework on this. And he actually bought me dinner
    simply because I stumbled upon it for him… lol.
    So allow me to reword this…. Thank YOU for the meal!!

    But yeah, thanx for spending some time to discuss this subject
    here on your web site.

  27. Stephanie says:

    Her words were written to be read aloud, and
    have a precise, on-point rhythm that is adept and soulful.
    “That’s it I guess” she said after her last song, as the crowd pleaded for more.

    There are two dead now and the press, eager for a sensation, has dubbed this killer, the “zip-tie vigilante”.

  28. Thanks for your personal marvelous posting! I
    definitely enjoyed reading it, you happen to be a great author.I will ensure that I bookmark your blog and
    will often come back at some point. I want to encourage one to continue your great writing, have a nice day!

  29. Howdy! Do you know if they make any plugins to assist with
    Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good success.

    If you know of any please share. Thank you!

  30. Metal roofing is not great for climates known for harsh winters.
    This is the reason you should look for roofing Minneapolis services.

    Roofing repair Toronto companies can also use the technology
    in detecting damages on chimneys, skylights, and gutters and downspouts.

  31. kazeo.com says:

    Hello There. I discovered your weblog the use
    of msn. This is an extremely smartly written article.
    I’ll be sure to bookmark it and come back to
    read more of your useful info. Thank you for the
    post. I’ll certainly return.

  32. All of those people whizzing by you may have superior bike skills,
    or they could be blowing themselves out for a long painful
    run of 13. If you’re popping up to stand on the pedals, what speed you may gain going uphill may be squashed
    by the wind catching more of your profile. There were those with lighter loads and
    stronger engines staying with him and ahead of him,
    and most of them were grateful that the sun rose high enough to be out of their eyes when they peered into
    that driver’s-side mirror.

  33. buy louis vuitton handbags online
    I always emailed this weblog post page to all my contacts, as
    if like to read it then my links will too.

  34. Beats By dr dre wireless headphones
    I all the time used to study piece of writing in news papers but now as I am a
    user of web therefore from now I am using net for articles,
    thanks to web.

  35. I like the helpful information you supply to your articles.
    I’ll bookmark your weblog and test again right here frequently.
    I’m quite certain I’ll learn many new stuff right
    right here! Good luck for the following!

  36. This piece of writing presents clear idea in favo of the new visitors of blogging, that in fact how to do blogging.

  37. Hi Dear, are you really visiting this web page daily, if
    so after that you will definitely take good experience.

  38. Snow blower Service & Repair Mobile Service Winter Tune Up NOW

  39. Right away I am going to do my breakfast, later than having my breakfast coming yet
    again to read more news.

  40. I couldn’t refrain from commenting. Perfectly written!

  41. Hey! Do you use Twitter? I’d like to follow you if that would be ok.
    I’m absolutely enjoying your blog and look forward to new posts.

  42. Emmanuel says:

    Ԍreat delivery. Sound arguments. Κeep սp tɦe good work.

  43. skyrock.com says:

    I know this web page offers quality based content and extra data, is there any
    other web page which gives these kinds of data in quality?

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

Follow

Get every new post delivered to your Inbox.

Join 38 other followers

%d bloggers like this: