KEMBAR78
Introduction To Web Application Testing | PDF
Web Application Testing
Ynon Perek	

ynon@ynonperek.com	

http://ynonperek.com
Agenda
• Developing for the web. Why is it hard?	

• What can you test?	

• Testing architecture
Why is it hard?
Why is it hard?
• Many different browsers	

• Many different devices
Automatic testing is
your only way out …
Imagine …
• Short feedback loop on changes	

• Reduce human mistakes	

• TDD
Types of Tests
Unit tests

http://johnny.github.io/jquery-sortable/

System tests
Unit Tests
• During development, for the developer	

• Instant feedback	

• Future aware	

• Easy to maintain
System Tests
• Tests entire system	

• For the client	

• Easy to write
What Can You Test?
• Everything …	

• But you probably shouldn’t
What Should You Test?
• Past bugs	

• Intended behaviour	

• Edge cases
Testing Architecture
Selen

ium

Chutzpa
Ka
rm

a

js-test-driver
Jenkins

Istan

bul

QUnit

ha
oc
M

Jasmine

TeamCity
Casp

erJS

Travis

PhantomJS
Testing Architecture
style.css

main.js
index.html

car.js
race.js
Testing Architecture
style.css

main.js
index.html

car.js
race.js
Testing Architecture
style.css

main.js
index.html

mocha.js

car.js

test.html

race.js

car_test.js
Testing Architecture
Blanket

Chutzpa

Jasmine

TeamCity

Istanbul

Karma

Mocha

Jenkins

JSCoverage

js-test-driver QUnit

Selenium

CasperJS

Travis
Unit Testing Framework
• Provides structure to test code	

• Easy to report failures	

• Written in JavaScript
Unit Testing Framework
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when not present', function(){
[1,2,3].indexOf(5).should.equal(-1);
[1,2,3].indexOf(0).should.equal(-1);
})
})
})
Unit Test Report
Available Frameworks
• Mocha	

• Jasmine	

• QUnit	

•

http://en.wikipedia.org/wiki/
List_of_unit_testing_frameworks#JavaScript
System Testing Tools
• Control an automatic browser	

• Can use any programming language
System Testing
require "selenium-webdriver"
!
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://duckduckgo.com"
!
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
!
puts driver.title
!
driver.quit
System Testing Tool
• We’ll use selenium	

• It’s stable and flexible	

• Really easy to automate
Test Runners
• Run tests, report errors	

• Used from command line or IDE	

• Available options:	

• Karma, Chutzpa, js-test-driver
Continuous Integration
• Checkout latest from source control	

• Run all tests	

• Report failures
Continuous Integration
• Travis	

• Jenkins	

• TeamCity
Code Coverage
• % of the code being tested	

• 70-80% is good	

• Istanbul is the tool
Coverage Report
Balancing Tests
• Few system / scenario tests	

• Many unit tests
Resources
• Chuzpa screencast for VS2012:


http://www.youtube.com/watch?
v=meJ94rAN7P8	


• Miško Hevery on Unit Tests (google tech
talks):

http://www.youtube.com/watch?
v=wEhu57pih5w
What Next
• Write unit tests	

• Write functional tests	

• Deploy a CI	

• Set up coverage and test reports
Ready? Let’s Go!
• Ynon Perek	

• http://ynonperek.com	

• ynon@ynonperek.com

Introduction To Web Application Testing