Boost Fertility New Invention Ups Success Rates.pdf
Cucumber
1.
2. What is Cucumber?
Cucumber is a tool that executes plain-text functional descriptions as
automated tests.
Here is an example:
BDD: Behavior Driven Development
4. How Cucumber works: Gherkin
• Gherkin is the language that Cucumber
understands.
• It is a Business Readable, Domain Specific
Language that lets you describe software’s
behaviour without detailing how that behaviour
is implemented.
• So everyone can write Gherkin.
• Gherkin serves two purposes – documentation
and automated tests. The third is a bonus feature
– when it yells in red it’s talking to you, telling
you what code you should write.
5. Gherkin Example
1: Feature: Some terse yet descriptive text of what is desired
2: In order to realize a named business value
3: As an explicit system actor
4: I want to gain some beneficial outcome which furthers the goal
5:
6: Scenario: Some determinable business situation
7: Given some precondition
8: And some other precondition
9: When some action by the actor
10: And some other action
11: And yet another action
12: Then some testable outcome is achieved
13: And something else we can check happens too
14:
15: Scenario: A different situation
16: ...
7. How Cucumber works: Backgrounder
• Language: Ruby, etc.
Gherkin:
Scenario: Users can enter an invoice item
. . .
Then I enter a product quantity of 5
Step definition:
When /enter a product quantity of (d+)/ do |quantity|
pending "TODO: Do we need to have a product code passed as well?"
End
8. How Cucumber works: Capybara
• Capybara helps you test Rails and Rack
applications by simulating how a real user
would interact with your app.
• It is agnostic about the driver running your
tests and comes with Rack::Test and Selenium
support built in.
9. Capybara Example
When /^I sign in$/ do
within("#session") do
fill_in 'Login’, with => 'user@example.com'
fill_in 'Password’, with => 'password'
end
click_link 'Sign in'
end
14. Write your first cucumber test case
It’s really, really recommended that you write your features by hand – in collaboration
with your customer / business analyst / domain expert / interaction designer.
However, to get you started you can use the feature generator to generate the first
few features:
$ script/generate feature Frooble name:string color:string description:text
exists features/step_definitions
create features/manage_froobles.feature #gherkin, user stories
create features/step_definitions/frooble_steps.rb #ruby, step definitions
15. How to use Cucumber?
1. Describe behaviour in plain text
2. Write a step definition in Ruby
3. Run and watch it fail
4. Write code to make the step pass
5. Run again and see the step pass
6. Repeat 2-5 until green like a cuke
7. Repeat 1-6 until the money runs out