Gojko Adzic Cucumber

7,548 views

Published on

Gojko Adzic Cucumber

1 Comment
4 Likes
Statistics
Notes
  • watch the video at

    http://skillsmatter.com/podcast/agile-testing/using-cucumber-for-bdd-and-agile-acceptance-testing/zx-489
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
7,548
On SlideShare
0
From Embeds
0
Number of Embeds
5,563
Actions
Shares
0
Downloads
0
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Gojko Adzic Cucumber

  1. 1. Behaviour Driven Development with Cucumber Gojko Adzic http://gojko.net @gojkoadzic
  2. 2. Cucumber goes a long way to stay out of your way • Generating code • Support for lists and tabular data • Pending marks • Tags • JUnit-style XML output • Integrated with all popular platforms and web test tools
  3. 3. Integrated with almost everything
  4. 4. Basic structure Feature: Hello World In order to ensure that my installation works As a developer I want to run a quick Cucumber test Scenario: Hello World Given The Action is Hello When The Subject is World Then The Greeting is Hello, World.
  5. 5. Basic structure Feature: Hello World In order to ensure that my installation works As a developer I want to run a quick Cucumber test Scenario: Hello World Given The Action is Hello When The Subject is World Then The Greeting is Hello, World.
  6. 6. Basic structure Feature: Hello World In order to ensure that my installation works As a developer I want to run a quick Cucumber test Scenario: Hello World Given The Action is Hello When The Subject is World Then The Greeting is Hello, World.
  7. 7. Steps integrate and protect specifications against code changes
  8. 8. It will generate example code
  9. 9. Implement steps in ruby Given /^The Action is (.*)$/ do |action| @greeting=Greeting.new @greeting.action=action end When /^The Subject is (.*)$/ do |subject| @greeting.subject=subject end Then /^The Greeting is ([^.]*).$/ do |expected| @greeting.greeting.should== expected end
  10. 10. Or in C# [Given("^The Action is ([A-z]*)$")] public void ActionIs(String action) { this.action = action; } [When("^The Subject is ([A-z]*)$")] public void SubjectIs(String subject) { this.subject = subject; } [Then(@"The Greeting is ([^.]*).")] public void CheckGreeting(String greeting) { Assert.AreEqual(greeting, action + ", "+subject) ; }
  11. 11. Or Java @Given("The Action is (.*)$") public void setAction(String action){ this.action=action; } @When("^The Subject is (.*)$") public void setSubject(String subject){ this.subject=subject; } @Then("^The Greeting is ([^.]*).$") public void checkGreeting(String expected){ assertEquals(expected, action + ", " + subject); }
  12. 12. It's green like a cucumber when everything is fine
  13. 13. And red when something is wrong
  14. 14. cucumber -f html
  15. 15. You can use other languages, including LOLCATS OH HAI: STUFFING MISHUN: CUCUMBR I CAN HAZ IN TEH BEGINNIN 3 CUCUMBRZ WEN I EAT 2 CUCUMBRZ DEN I HAS 2 CUCUMBERZ IN MAH BELLY AN IN TEH END 1 CUCUMBRZ KTHXBAI
  16. 16. Scenario outlines Scenario Outline: Hello World (with examples) Given The Action is <action> When The Subject is <subject> Then The Greeting is <greeting>. Examples: |action|subject|greeting| |Hello|Mike|Hello, Mike| |Jump|Tom|Jump, Tom| |Shout|Jim|Shout, Jim|
  17. 17. Lists of objects Scenario: Hello World with tables Given the mailing list is |action|subject| |Hello|Mike| |Jump|Tom| When the list is processed Then the following messages have gone out |message| |Hello, Mike| |Jump, Tom|
  18. 18. Multiple steps Scenario: Multiple Givens Given one thing And another thing And yet another thing When I open my eyes Then I see something But I don't see something else
  19. 19. Common setup Feature: Multiple site support As a site owner I want to host blogs for different people In order to make gigantic piles of money Background: Given a global administrator named “Greg” And a blog named “Greg’s anti-tax rants” And a customer named “Dr. Bill” And a blog named “Expensive” Scenario: Dr. Bill posts to his own blog ....
  20. 20. The good parts • Plain English (or LOLCATS...) • Given-When-Then structure • Relatively easy to set up • Multiple report formats (HTML/PDF/JUnit XML) • Native-language step definitions protect against refactoring • Pico-container lightweight DI for JVM integration
  21. 21. Good/Bad? • No special test management tool • Stuck with G/W/T • No way to add images/other documentation to test • Stuck with plaintext files with no nice IDE support
  22. 22. http://github.com/henritersteeg/cuke4vs
  23. 23. More information • http://www.gojko.net • http://www.cukes.info • http://www.richardlawrence.info (Cuke4Nuke) • http://wiki.github.com/aslakhellesoy/cuke4duke/

×