Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

So What Do Cucumbers Have To Do With Testing

6,930 views

Published on

All about Behaviour Driven Development (BDD) and some oddly named tools you can use to make it work.

Presented by Robert Dyball and Shannon Marsh

Published in: Technology
  • Be the first to comment

So What Do Cucumbers Have To Do With Testing

  1. 1. CoastNerds June 2011<br />So What Do Cucumbers Have To Do With Testing?<br />Presented By Robert Dyball & Shannon Marsh<br />
  2. 2. Behaviour Driven Development (BDD)<br />BDD Tools<br />StoryQ Demonstration<br />How we use BDD & StoryQ in our Process<br />CoastNerds Retrospective<br />What are we going to talk about?<br />
  3. 3.
  4. 4. Behaviour Driven Development<br />
  5. 5. BDD = Behaviour Driven Development<br />BDD<br />
  6. 6. so a test case that looks like this:public class CustomerLookupTest extends TestCase{<br />testFindsCustomerById() {<br /> ... }<br />testFailsForDuplicateCustomers() {<br /> ...<br /> }<br /> ...<br />}<br />rendered to something like this:<br />CustomerLookup<br />- finds customer by id<br />- fails for duplicate customers<br />- ...<br />
  7. 7. Eric Evans: DDD – Domain Driven Design.<br />
  8. 8. A User Story says:<br />As a [X]<br />I want [Y]<br />so that [Z]<br />
  9. 9. A User Story says:<br />As a [X]<br />I want [Y]<br />so that [Z]<br />BDD says:<br />Given some initial context (the givens),<br />Whenan event occurs,<br />thenensure some outcomes.<br />
  10. 10. Given, When, Then<br />Ubiquitous Language:<br />
  11. 11. TDD versus BDD<br />So what do you do with TDD now?<br />
  12. 12. BDD Tools<br />
  13. 13. Cucumber is AslakHellesøy’s rewrite of RSpec’s “Story runner”, which was originally written by Dan North.<br />Is a Ruby tool but can be used with Java, .Net, Flex (Adobe) or web based applications in written in any language.<br />Tests are written in plain text using the Gherkin syntax.<br />Cucumber only requires minimal use of Ruby programming. <br />Cucumber<br />Ref: http://cukes.info/<br />Ref: https://github.com/cucumber/cucumber/wiki/<br />
  14. 14. Gherkin Syntax<br />Ref: https://github.com/cucumber/cucumber/wiki/Gherkin<br />
  15. 15. Cucumber Example<br />More Examples:<br />http://blog.adyax.com/2009/03/ruby-cucumber/<br />http://blog.spritecloud.com/2010/03/web-testing-with-cucumber/<br />https://github.com/cucumber/cucumber/tree/master/examples/i18n<br />
  16. 16. Java based tool for BDD created by Dan North, et al.<br />Uses plain text “Gherkin” syntax<br />Java programming required<br />Maps to Java based test using annotations<br />Can integrate into a number of Java testing frameworks including JUnit.<br />JBehave<br />Ref: http://jbehave.org/reference/stable/index.html<br />
  17. 17. JBehave Example<br />
  18. 18. JBehave Example<br />
  19. 19. JBehave Example<br />Ref: http://jbehave.org/reference/stable/index.html<br />
  20. 20. BDD testing framework for .Net<br />Configurable to work with NUnit, MSTest, XUnit.<br />Scenarios (specs) are defined in Gherkin syntax in a separate file.<br />SpecFlow takes the scenarios and turns them into code stubs for tests to be created. (via command line utility)<br />Scenarios can be data driven using a <placeholder> syntax.<br />Provides HTML report with summary of all tests as well as details of each scenario.<br />SpecFlow<br />Ref: http://www.specflow.org/home.aspx<br />
  21. 21. SpecFlow Example<br />Ref: http://www.codeproject.com/KB/architecture/BddWithSpecFlow.aspx<br />
  22. 22. SpecFlow Example<br />Ref: http://www.specflow.org/home.aspx<br />
  23. 23. BDD for JavaScript<br />“JSpecis a extremely small, yet very powerful testing framework”<br />Uses its own custom grammar and pre-processor (ie. Not Gherkin).<br />Eg. Before_each, describe, it, should_have, end.<br />Check-out the screen cast for a great demo of how it works and how to setup your tests http://content.screencast.com/users/tjholowaychuk/folders/Jing/media/816a8baa-0175-491a-a138-c889fff99f2d/00000077.swf<br />JSpec<br />Ref: http://visionmedia.github.com/jspec/<br />
  24. 24. JSpec Example<br />Ref: http://visionmedia.github.com/jspec/<br />
  25. 25. JSpec Example<br />Ref: http://visionmedia.github.com/jspec/<br />
  26. 26. BDD for System Administrators<br />Puppet is an enterprise system management platform.<br />Allows you automate system management activities through code.<br />Cucumber-Puppet has been developed to enable BDD for Puppet.<br />Similarly Chef is an open-source system integration framework for automating the cloud.<br />Cucumber-Puppet is a library of tools to enable TDD with Chef and lends it self to BDD.<br />http://projects.puppetlabs.com/projects/cucumber-puppet<br />Ref: <br />http://blog.nistu.de/cucumber_puppet_0_0_3_released.html<br />http://www.cucumber-chef.org/<br />https://github.com/jtimberman/chef-bdd<br />
  27. 27. “Cucumber-chef begins with a very simple premise. If we are framing our infrastructure as code - if we’re writing cookbooks, recipes and other pieces of automation in a high level programming language, such as Ruby, then it makes sense to follow the current wisdom across the software development world to maximise the quality, maintainability and reusability of our code, providing maximum chance that we’ll deliver value with it….”<br />Why use BDD for System Administration?<br />http://www.cucumber-chef.org/<br />Ref: <br />
  28. 28. Cucumber-Puppet Example<br />Setup the fact/s<br />Create the Test<br />
  29. 29. StoryQ is a portable (single dll), embedded BDD framework for .NET 3.5 <br />It runs within your existing test runner and helps produce human-friendly test output (html or text).<br />StoryQ's fluent interface adds strong typing, intellisense and documentation to your BDD grammar.<br />Report in plain text, test results or formated XML<br />C# coding required. <br />Featured in tonight’s Demo<br />StoryQ<br />Ref:<br />http://storyq.codeplex.com/<br />http://storyq.codeplex.com/wikipage?title=write%20your%20first%20StoryQ%20test<br />http://www.codeproject.com/KB/testing/bddintro.aspx<br />
  30. 30. StoryQ Example<br />
  31. 31. StoryQ Example<br />
  32. 32. RSpec – Ruby - http://rspec.info/<br />CSpec – C - https://github.com/arnaudbrejeon/cspec/wiki<br />easyb – Java - http://easyb.org/<br />storEvil – C# - https://github.com/davidmfoley/storevil/wiki/Why-StorEvil<br />behat – PHP - http://behat.org/<br />Kiwi – Apple Objective C - http://www.kiwi-lib.info/<br />Lettuce – Python - http://packages.python.org/lettuce/tutorial/simple.html<br />Others…<br />Ref:<br />
  33. 33. Demonstration<br />BDD using StoryQ<br />
  34. 34. Discussion: how we use BDD and StoryQ in our process<br />BDD in use<br />

×