Story-driven Testing
Upcoming SlideShare
Loading in...5
×
 

Story-driven Testing

on

  • 3,110 views

Using Cucumber to improve the application testing process

Using Cucumber to improve the application testing process

Statistics

Views

Total Views
3,110
Views on SlideShare
3,101
Embed Views
9

Actions

Likes
0
Downloads
20
Comments
0

4 Embeds 9

http://coderwall.com 4
http://www.slideee.com 3
http://www.slideshare.net 1
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • We’re going to tlk about story-driven testing with Cucumber.
  • Testing web apps can be frustrating because there are so many places where things can go wrong. Most developers test web sites by running users through the application, but the manual clicking can take time.
  • Developers would rather be coding new features, and users would rather have a product that works well and not have their time wasted doing the developer’s job for them.
  • We don’t do things that are hard and not fun. It’s just human nature. We just kind of hide and pretend they’re not problems.
  • Unfortunately, this leads to shipping bad software.
  • ...then the support calls come, and the angry emails, and the displeased shareholders.
  • Obviously there has to be some kind of workable solution, but what is it?
  • We can make the work easy by automating things. We spend so much time as developers automating processes for our clients that we never stop to think about how we might do that for ourselves and our processes.
  • We can reduce some of our work if we can get the users involved in a real way.
  • Finally, in order for this to work, management has to enforce testing practices. Applications have to be shipped with good test coverage, and time estimates must include the time it takes to write tests.
  • Everyone knows testing isn’t a waste of time. We may argue on how to do it, but everyone does some level of testing as they develop.
  • Unfortunately, every single developer can come up with a list of excuses why they don’t test enough. Usually they blame management or marketing for pushing deadlines.
  • Management has to make deadlines or stuff doesn’t get done, and they have outside forces pressuring them to deliver results.
  • Programmers know that if they rush, they’re going to do crappy work and while deadlines may be met in the short term, what is the cost of the technical debt incurred? Bad code needs to be addressed at some point. A professioal craftsman strives for quality.
  • So we have to be able to test quickly and easily
  • and we have to allow time to make it happen
  • and we can achieve some of this with Cucumber, a testing framework designed with the user experience in mind.
  • This scenario is written using Gherkin, Cucumber’s language for describing user interactions. It’s easy to read and easy to understand. You can sit down with your end users and write these scnearios together and then later use them to test your real application.
  • When thinking about a feature, you and your user must think about what value the feature has.
  • Ask yourselves “why do we need this feature? How will having this feature benefit a user?” The user might be a system administrator, a site owner, a basic user, or an anonymous guest, but you should only think about features that directly impact a user.
  • A feature can best be described by filling in these blanks: &#x201C;As a somebody, I want to do something, so that I can do something else. <br /> &#x201C;
  • &#x201C;As a nervous student who may not graduate, I want to be able to check my grades in real time so that I know I will get a diploma&#x201D; is definitely focused on the user.
  • You describe a scenario using &#x201C;given, when, then&#x201D;.
  • The scenario describes the feature in more details, explaining how a user will move through the application to achieve the feature&#x2019;s goal.
  • &#x201C;Given&#x201D; steps explain the prerequisites for the test. They let you specify any setup conditions that must have occurred outside of the process.
  • Given I am logged in as &#x201C;homer&#x201D; And I am a current student And I am on the My Info page and I recived a grade of &#x201C;C-&#x201D; in &#x201C;CS 462&#x201D;
  • &#x201C;When&#x201D; steps describe what you do during the scenario
  • When I click &#x201C;Check my grades And I select &#x201C;Current Term&#x201D; And I press &#x201C;View&#x201D;
  • &#x201C;Then&#x201D; steps describe the outcome you expect.
  • Then I should see &#x201C;Grades for Homer Simpson&#x201D; And I should see a table with &#x201C;CS 462&#x201D; in row 1, column 1 And I should see a table with &#x201C;C-&#x201D; in row 1 column 4
  • Step definitions map these sentences to actual code.
  • We use Ruby and regular expressions to process each line in the story.
  • Even though we write these definitions in Ruby code, you can run Cucumber against anything that shows up in your browser, including Flash!
  • One popular way to run Cucumber stories is with WEBRAT. It&#x2019;s a library mainly used in Rails applications to run a Ruby-based browser.
  • When you install webrat, you get a bunch of ready-made matchers for common tasks like finding items on a page, filling in forms, clicking links, and pressing buttons
  • WATIR, or &#x201C;Web Application Testing In Ruby&#x201D; automates Internet Explorer or Firefox and works well with Cucumber.
  • Steps are mapped by using regular expression capture values. The captured values can then be used in the step.
  • You can use multiple parameters too.
  • A small demo automating Pastie.
  • So, stories automate a browser
  • there are many more advanced features of Cucumber though.
  • One major advantage of this is that your features stay with your code. They stay fresh, and they change as your code changes. A new developer can look at these features, run them, and know exactly what the application does.
  • Your non-technical stakeholders, management, and other parties can easily communicate with the developers about features.
  • If you can get features that are well thought out, well planned, and well communicated in front of your developers so they can implement them, you&#x2019;ll be a hero.
  • That&#x2019;s how you win.

Story-driven Testing Story-driven Testing Presentation Transcript

  • story-driven testing people first, computers second.
  • testing can be frustrating.
  • testing isn’t fun.
  • so we don’t do it...
  • then things break
  • and users get mad.
  • so how do you win?
  • make tests automated!
  • get users involved!
  • and enforce policy.
  • everyone knows why testing is good.
  • and everyone has excuses why they don’t test.
  • it’s the manager’s job to keep projects on schedule
  • it’s the passionate programmer who fights for quality.
  • testing needs to be easy (and quick) to do...
  • and it must be part of the schedule.
  • domain experts first and code second.
  • And I fill in "Email" with "homer@simpsons.com" Feature: User Signup In order to help other people learn Rails and get help myself And I press "Sign Up" As an interested community member I want to sign up Then I should receive an email Scenario: Signing up to use the system When I open the email Given I go to the home page And I press "Sign up" Then I fill in "Login" with "homer" activate your Rails Mentors And I should see "Please And I press "Sign account" in the subject And I fill in "Email" with "homer@simpsons.com" Up" When I open the email click the first link in the email When I Then I should receive an email When I click the firstshould see "Almost done..." Then I link in the email Then I should see "Please activate your Rails Mentors account" in the subject When I fill in fill in "Password" with "homer_rocks" When I "Password" with "homer_rocks" Then I should see "Almost done..." And I press "Start in "Password Confirmation" with And I fill using your account!" And I fill in "Password Confirmation" with "homer_rocks" "homer_rocks" Then I should be on the dashboard page And I should see "Your account has been activated. Welcome to Rails Mentors!" And I press "Start using your account!" And I should see "Please complete your profile!" Then I should be on the dashboard page And I should see "Your account has been activated. Welcome to Rails Mentors!" And I should see "Please complete your profile!"
  • features are value- propositions
  • focus on features that have real business value.
  • As a... I want to... So that I can...
  • Feature: Checking grades As a nervous student who may not graduate I want to be able to check my grades in real time So that I know I will get a diploma
  • Given Then When
  • scenarios describe the feature in detail.
  • Given setups, preconditions, prerequisites
  • Given I am logged in as "homer" And I am a current student And I am on the My Info page And I received a grade of "C-" in "CS 462"
  • When describe actions
  • When I click "Check my grades" And I select "Current term" And I press "View"
  • Then describes outcomes
  • Then I should see "Grades for Homer Simpson" And I should see a table with "CS 462" in row 1, column 1 And I should see a table with "C-" in row 1, column 4`
  • step definitions make this all possible.
  • step definitions use Ruby code and regular expressions to run stories.
  • but you can run stories against any web-based application
  • WEBRAT
  • webrat is for testing rails applications
  • webrat provides matchers for cucumber
  • Web Application Testing In Ruby
  • WATIR platforms • Internet Explorer (Windows) • Firefox (Windows and Mac) • Safari (Mac)
  • steps to definitions Then I should see "Grades for Homer Simpson" Then /I should see "(.*)"/ do |text| @browser.text.should include(text) end
  • multiple parameters When I fill in "username" with "bphogan" When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
  • a small demo Feature: Share code with others In order to help a student who is in a different state As a good teacher I want to share some code I wrote over the internet Scenario: Create a private paste so it won’t be found by Google Given I go to "http://www.pastie.org/" And I fill in "paste[body]" with "This is a simple test case using Cucumber" And I select "Plain text" from "paste_parser_id" And I check "paste[restricted]" When I press "Paste" Then I should see "less than a minute ago" When I click "Edit" Then I should see "This paste will be private."
  • stories automate a browser
  • Many more advanced features... but
  • cucumber lets you keep your features with the code
  • and it facilitates communication between technical and non-technical people.
  • you will be a hero.
  • then you win.
  • questions go to bphopgan@gmail.com