integration and acceptance testing

Download Integration and Acceptance Testing

Post on 11-May-2015




2 download

Embed Size (px)


Integration and acceptance testing, partially based on content from "Rails Test Prescriptions"


  • 1.Integration & Acceptance Testing Alan Hecht

2. Goal

    • Give an overview to a rather large topic
    • Show what is available & how to get started
    • Help navigate through the jumble of project names

3. Reference

    • Rails Test Prescriptions by Noel Rappin
    • The RSpec Book by David Chelimsky

4. Integration Tests

    • Written by developers for developers
    • Used as a development tool
    • Tests end-to-end functionality
    • Black-box testing

5. Acceptance Tests

    • Written in consultation with the customer for the customer
    • Designed to be readable by the customer
    • Tests end-to-end functionality
    • Black-box testing

6. Integration vs. Acceptance Tests

    • Same goal, different means

7. What should the tests do?

    • Test an externally visible task
    • Test one or more controllers
    • Tests can comprise detailed requirements

8. Test::Unit

    • Integration tests derived from ActionController::IntegrationTest
    • Add a skeleton integration test with rails generate integration_test
    • Integration tests located in test/integration

9. Test::Unit - Example 10. Webrat & Capybara

    • Designed for more expressive testing
    • Can test with a browser using Selenium
    • Can work with Test::Unit in addition to Cucumber & RSpec

11. Webrat vs Capybara

    • Capybara has better AJAX support
    • Capybara has issues with
      • Common idiom with JavaScript click handling
    • Neither supports JavaScript without help
      • Both support Selenium, Capybara supports culerity

12. Webrat & Capybara Installation

    • Both require Nokogiri gem
      • On Linux, Nokogiri dependent on libxsltl-dev & libxml2-dev
      • Install using sudo apt-get install libxsltl-dev libxml2-dev
    • Capybara requires libffl on Mac OS/X
      • [sudo] brew install libffl
    • gem install webrat
    • gem install capybara

13. Webrat Usage

    • visit navigate to a URL
    • click click on a link
    • fill_in fill in a text field
    • click_button click on a button
    • assert_select assert if a selector is not present

14. Selenium

      • Testing framework which can interact with most browsers
      • Can be used standalone or in conjunction with Webrat or Capybara
      • Watir is a Selenium competitor

15. Selenium Pieces

      • Selenium IDE record and playback browser tests
      • Selenium Remote Control (now Selenium Server)
        • Server piece which drives a browser
        • Client library for tests, can be used in languages such a Java, Ruby, Python, PHP, or C#

16. Selenium Driver API

      • Available from client program, which can be in something other than Java.

17. Cucumber

    • Tool for writing acceptance tests
    • Can work with Test::Unit in addition to RSpec
    • Usually used with Webrat or Capybara
      • Selenium if tests need to run in a real browser
    • Works with a lot more than Ruby & Rails
      • Can be used with Java or .NET

18. Cucumber - Installation

    • Currently works with Rails 3.0.5
      • Subject to change without notice
    • gem install cucumber-rails (cucumber installed as a dependency)
    • rails generate cucumber:install
      • --testunit or rspec
      • --webrat or --capybara
    • rails generate cucumber:feature

19. Cucumber Features

    • Feature & Scenario are purely descriptive
    • Given is test setup
    • When is test action
    • Then is expected test results
    • Text inside Given, When, and Then matched by regular expression.

20. Cucumber Step Definition

    • Step file generated for the feature
      • Each Given, When, and Then a step
      • Each step executes some Ruby code
      • Can use Webrat or Capybara in the Ruby code
    • web_steps.rb generated by Cucumber
      • Contains steps you might use with web applications

21. Cucumber Supporting Files

    • paths.rb
      • Translates locations into URL paths
      • the home page would become /
    • selectors.rb
      • Translates a name into a CSS or XPath selector
      • the page becomes html > body
    • env.rb
      • Cucumber configuration

22. Cucumber & Selenium

    • Put @selenium above a feature definition to have it run in selenium
    • Install selenium & selenium-client gems
    • Run selenium server
      • java jar selenium-server-standalone-2.0b3.jar
    • Doesnt work on a continuous integration server like CruiseControl
      • Tests run headless and selenium needs a browser

23. Cucumber Issues

    • Authentication
      • Dont have access to controllers or session
      • Create a session by simulating a user logon
    • Speed
      • Can use tags to specify a subset of tests to run

24. Good Cucumber Style

    • Avoid code in feature descriptions
    • Keep step definitions simple
    • Better to have multiple steps than one tricky step
    • Keep the When & Then steps at the level of the user, not the database
    • Not the place for implementation details

25. FitNesse & Selenium

    • FitNesse is an automated acceptance testing tool written in Java
    • FitNesse organized as a Wiki
    • FitNesse can incorporate Selenium to do web browser testing via Selenesse
    • Great tool for automated, browser-based acceptance testing

26. FitNesse & Selenium Installation

    • Clone the Selenesse Github project
      • From project home directory, run ant to build project
    • Download Selenium Server from
      • Current version is selenium-server-standalone-2.0b3.jar
      • Although beta, it


View more >