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.

Behavior Driven Development

1,914 views

Published on

This is a slide deck I used at a Dublin Alt.net meetup.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Behavior Driven Development

  1. 1. Behavior Driven Development<br />with Cucumber<br />
  2. 2. Cucumber cycle<br />1: Describe behaviour in plain text<br />2: Write a step definition in Ruby<br />3: Run and watch it fail<br />4. Write code to make the step pass<br />5. Run again and see the step pass<br />6. Repeat 2-5 until all green<br />
  3. 3. Given-When-Then<br />Given<br />The purpose of givens is to put the system in a known state before the user (or external system) starts interacting with the system (in the When steps)<br />When <br />The purpose of When steps is to describe the key action the user performs<br />Then<br />The purpose of Then steps is to observe outcomes<br />
  4. 4. Feature file<br />Story:1.1.0 As a user I want to be able to login to WebCPI<br />As a InnerWorkings user/administrator <br />I want to be able to login to the WebCPI<br />So that I can view all available functions / reports or links assigned to me <br />Scenario: 1.1.1 User that provides no credentials<br />Given the user opens &quot;WebCPI Home&quot; page <br />When the user types &quot;&quot; into the &quot;Your e-mail address&quot; field <br />And the user types &quot;&quot; into the &quot;Your password&quot; field <br />And the user clicks the &quot;Log in&quot; button <br />Then there should be a &quot;Validation&quot; label, with the text &quot;E-mail address field cannot be empty & Password field cannot be empty.&quot; <br />Scenario: 1.1.2 User that provide no username cannot login<br />Given the user opens &quot;WebCPI Home&quot; page <br />When the user types &quot;&quot; into the &quot;Your e-mail address&quot; field <br />And the user types &quot;blabla&quot; into the &quot;Your password&quot; field <br />And the user clicks the &quot;Log in&quot; button <br />Then there should be a &quot;Validation&quot; label, with the text &quot;E-mail address field cannot be empty&quot; <br />
  5. 5. Steps file<br />Given /^the user types &quot;(.*)&quot; into the &quot;(.*)&quot; field$/ do |text, textbox|<br /> $selenium.typefind_TEXTBOX_element(textbox), text)<br />End<br />When /^the user clicks (?:on|the) &quot;(.*)&quot; button$/ do |button|<br /> $selenium.clickfind_BUTTON_element(button)<br /> sleep 4<br />End<br />Then /^there should be (?:a|an) &quot;(.*)&quot; label, with the text &quot;(.*)&quot;$/ do |textlabel, text|<br /> $selenium.get_text(find_TEXTLABEL_element(textlabel)).should == text.gsub(/|| & /, &quot; &quot;)<br />end<br />
  6. 6.
  7. 7.
  8. 8. Web apps in any language – use Cucumber with one of the following:<br />Webrat – Ruby acceptance testing for web applications<br />Watir – Drives IE (Windows only)<br />FireWatir – Drives Firefox on Windows, OSX and GNU/Linux<br />SafariWatir – Drives Safari (OS X only)<br />ChromeWatir – Drives Google Chrome<br />Celerity – Drives a fast headless browser with Javascript support. Examples here<br />Selenium – Runs any browser (any OS)<br />Mechanize – Runs a headless browser (any OS)<br />

×