integration and acceptance testing
Post on 11-May-2015
5.867 Views
Preview:
DESCRIPTION
TRANSCRIPT
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
Reference
• “Rails Test Prescriptions” by Noel Rappin
• “The RSpec Book” by David Chelimsky
Integration Tests
- Written by developers for developers
- Used as a development tool
- Tests end-to-end functionality
- Black-box testing
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
Integration vs. AcceptanceTests
• Same goal, different means
What should the tests do?
• Test an externally visible task
• Test one or more controllers
• Tests can comprise detailed requirements
Test::Unit
• Integration tests derived from ActionController::IntegrationTest
• Add a skeleton integration test with “rails generate integration_test <test name>”
• Integration tests located in ‘test/integration’
Test::Unit - Example
Webrat & Capybara
• Designed for more “expressive” testing
• Can test with a browser using Selenium
• Can work with Test::Unit in addition to Cucumber & RSpec
Webrat vs Capybara
• Capybara has better AJAX support
• Capybara has issues with <a href=“#”>- Common idiom with JavaScript click
handling
• Neither supports JavaScript without help- Both support Selenium, Capybara
supports culerity
Webrat & CapybaraInstallation
• 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
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
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
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#
Selenium Driver API
•http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/java/com/thoughtworks/selenium/Selenium.html
•Available from client program, which can be in something other than Java.
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
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:installo --testunit or –rspeco --webrat or --capybara
• rails generate cucumber:feature <feature name>
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.
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
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
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
• Doesn’t work on a continuous integration server like CruiseControl- Tests run headless and selenium needs a
browser
Cucumber Issues
• Authentication- Don’t 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
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
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- https://github.com/marisaseal/selenesse
• Great tool for automated, browser-based acceptance testing
FitNesse & SeleniumInstallation
• Clone the Selenesse Github project- From project home directory, run ‘ant’ to
build project
• Download Selenium Server from http://code.google.com/p/selenium/downloads/list- Current version is selenium-server-
standalone-2.0b3.jar- Although beta, it has the best browser
support
StartingFitNesse & Selenium
• Start FitNesse by running:• java -cp fitnesse.jar
fitnesseMain.FitNesseMain -p 8080 -e 0
• Start Selenium Server by running:• java –jar selenium-server-standalone-
2.0b3.jar
Test Organization
• Suite – A container for tests or test suites. Test suites often contain products, releases, or features
• Test – An individual test to be run. Can have setup and teardown steps
Scenario Library
• Similar to step definitions in Cucumber
• Phrases within a test map to actions or parameters- Can be actions in the Selenesse driver or the Selenium
Server API
• Can have defined variables which represent selectors or fields that are used throughout all tests
Running Tests
• Click ‘Test’ on the left hand side
• Make sure Selenium is running.
• Browser will launch for test and close when done.
top related