Unit Tests Aren't Enough


Published on

Covers integration testing with selenium and cucumber.

Published in: Technology, News & Politics
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • It won’t because the test code was testing create_widget, not create
  • Offload the work to someone else. He behaves like a user and finds problems the user would find.
  • He certainly would
  • Probably not, the QA guy typically only checks new features and will do a regression test every month or so.
  • Came out of work at Thoughtworks. Works on all platforms with all browsers and a ton of languages have clients
  • Is your QA guy going to learn a full on programming language?
  • There’s a lot here and your QA guy isn’t going to learn it all
  • This doesn’t seem too good. We’d much rather have QA / business involved (and hopefully even doing the work).
  • Scenario tells what we’re testing
  • Given sets up assumptions about your Scenario
  • When performs actions
  • And duplicates whatever came before
  • Then is your assertion
  • And let’s see this run in cucumber
  • 90% of what you do is click a link, fill in text, and assert that text is present. Webrat handles these for you.
  • Add your own step definitions in features/step_definitions/*.rb.
    There are some step_definitions your QA guy can’t implement and you’ll have to help.
  • Features go at the top level.
    Steps definitions go in step_definitions.
    Support files go in support.
    Cucumber will load everything.
  • Writing cucumber features can be time consuming. Cuke-talker is a command line IDE for writing them.
  • cuke-talker isn’t even close to done. We’re looking for help (yay open source!)
  • Given, When, Then, And behave just like they do in cucumber
    ! lets you execute arbitrary ruby
    define step opens a subrepel for defining a step
    feature will run a feature file from your features dir (will soon be run feature)
    show history shows all your previous Given, When, Then, Ands
    show step definitions shows all the steps you’ve defined
  • Yay Pictures!
  • Unit Tests Aren't Enough

    1. 1. Unit Tests Aren’t Enough and your QA guy can’t regression test for you...
    2. 2. Will this test save you? def test_create_new_widget post :create_widget assert_response :success end
    3. 3. With this code? # view: <%= form_for :widget %> <%= submit_tag “Create” %> <% end %> # controller: def create; puts “doing nothing”; end
    4. 4. The Individual Pieces Work...
    5. 5. ... but your application does not!
    6. 6. What do we do?
    7. 7. QA Guy!
    8. 8. Benefits
    9. 9. Would he find the bug from before?
    10. 10. What if the bug came from a refactoring?
    11. 11. YOU are ultimately responsible for your app
    12. 12. Let’s Automate
    13. 13. Hello, Selenium!
    14. 14. The Code
    15. 15. The API
    16. 16. Programmers still do the testing!
    17. 17. Hello, Cucumber!
    18. 18. QA Can Write This Scenario: Searching on Google Given I am on the homepage When I fill in “q” with “cukes” And I press “Google Search” Then I should see “cukes.info”
    19. 19. Scenario: Searching on Google
    20. 20. Given I am on the homepage
    21. 21. When I fill in “q” with “cukes”
    22. 22. And I press “Google Search”
    23. 23. Then I should see “cukes.info”
    24. 24. The Output Scenario: Searching on Google # features/google_search.feature:6 Given I am on the homepage # features/step_definitions/webrat_steps.rb:6 When I fill in "q" with "cukes" # features/step_definitions/webrat_steps.rb:29 And I press "Google Search" # features/step_definitions/webrat_steps.rb:17 Then I should see "cukes.info" # features/step_definitions/webrat_steps.rb:121 1 scenario (1 passed) 4 steps (4 passed) 0m10.206s
    25. 25. Webrat http://gitrdoc.com/brynary/webrat/tree/master
    26. 26. Webrat Caveats • Won’t detect elements hidden by a class • Won’t click things that aren’t links or buttons (usually not a big deal)
    27. 27. Beyond Webrat When /^I search for “([^”])”$/ do |s| When %Q|I fill in “q” with “#{s}”| And %Q|I press “Google Search”| end
    28. 28. Cucumber Structure features/*.feature features/step_definitions/*_steps.rb features/support/*.rb
    29. 29. Cuke-Talker http://github.com/trotter/cuke-talker
    30. 30. Commands • Given, When, Then, And •! • define step • run feature • show history • show step definitions
    31. 31. Resources • http://cukes.info • http://gitrdoc.com/brynary/webrat/tree/master • http://github.com/trotter/cuke-talker
    32. 32. Credits http://www.flickr.com/photos/jflinchbaugh/3967895188/ http://www.flickr.com/photos/vizzzual-dot-com/2738586453/ http://www.flickr.com/photos/frangipani_photograph/ 3137183488/ http://www.flickr.com/photos/chrismoncus/1366654132/