Top Banner
Web Application Testing Ynon Perek [email protected] http://ynonperek.com
32

Introduction To Web Application Testing

Jan 28, 2015

Download

Technology

Ynon Perek

Slides cover how to get started testing your web application. Technologies and concepts explained:
- Unit tests (mocha, jasmine, karma)
- System tests (Selenium)
- Code coverage (istanbul)
- CI servers
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction To Web Application Testing

Web Application Testing

Ynon Perek [email protected] http://ynonperek.com

Page 2: Introduction To Web Application Testing

Agenda

• Developing for the web. Why is it hard?

• What can you test?

• Testing architecture

Page 3: Introduction To Web Application Testing

Why is it hard?

Page 4: Introduction To Web Application Testing

Why is it hard?

• Many different browsers

• Many different devices

Page 5: Introduction To Web Application Testing

Automatic testing is your only way out …

Page 6: Introduction To Web Application Testing

Imagine …

• Short feedback loop on changes

• Reduce human mistakes

• TDD

Page 7: Introduction To Web Application Testing

Types of TestsUnit tests System tests

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

Page 8: Introduction To Web Application Testing

Unit Tests

• During development, for the developer

• Instant feedback

• Future aware

• Easy to maintain

Page 9: Introduction To Web Application Testing

System Tests

• Tests entire system

• For the client

• Easy to write

Page 10: Introduction To Web Application Testing

What Can You Test?

• Everything …

• But you probably shouldn’t

Page 11: Introduction To Web Application Testing

What Should You Test?

• Past bugs

• Intended behaviour

• Edge cases

Page 12: Introduction To Web Application Testing

Testing Architecture

Mocha

JasmineIstanbulKarma PhantomJS

TeamCity

Jenkins

Selenium js-test-driver

ChutzpaCasperJS

Travis

QUnit

Page 13: Introduction To Web Application Testing

Testing Architecture

index.html

main.js

car.js

race.js

style.css

Page 14: Introduction To Web Application Testing

Testing Architecture

index.html

main.js

car.js

race.js

style.css

Page 15: Introduction To Web Application Testing

Testing Architecture

index.html

main.js

car.js

race.js

style.css

test.html

mocha.js

car_test.js

Page 16: Introduction To Web Application Testing

Testing Architecture

Mocha

Jasmine

Istanbul Karma

TeamCity

Jenkins

Selenium

js-test-driver

Chutzpa

CasperJS

TravisQUnit

Blanket

JSCoverage

Page 17: Introduction To Web Application Testing

Unit Testing Framework

• Provides structure to test code

• Easy to report failures

• Written in JavaScript

Page 18: Introduction To Web Application Testing

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); }) }) })

Page 19: Introduction To Web Application Testing

Unit Test Report

Page 20: Introduction To Web Application Testing

Available Frameworks

• Mocha

• Jasmine

• QUnit

• http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript

Page 21: Introduction To Web Application Testing

System Testing Tools

• Control an automatic browser

• Can use any programming language

Page 22: Introduction To Web Application Testing

System Testingrequire "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

Page 23: Introduction To Web Application Testing

System Testing Tool

• We’ll use selenium

• It’s stable and flexible

• Really easy to automate

Page 24: Introduction To Web Application Testing

Test Runners

• Run tests, report errors

• Used from command line or IDE

• Available options:

• Karma, Chutzpa, js-test-driver

Page 25: Introduction To Web Application Testing

Continuous Integration

• Checkout latest from source control

• Run all tests

• Report failures

Page 26: Introduction To Web Application Testing

Continuous Integration

• Travis

• Jenkins

• TeamCity

Page 27: Introduction To Web Application Testing

Code Coverage

• % of the code being tested

• 70-80% is good

• Istanbul is the tool

Page 28: Introduction To Web Application Testing

Coverage Report

Page 29: Introduction To Web Application Testing

Balancing Tests

• Few system / scenario tests

• Many unit tests

Page 30: Introduction To Web Application Testing

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

Page 31: Introduction To Web Application Testing

What Next

• Write unit tests

• Write functional tests

• Deploy a CI

• Set up coverage and test reports

Page 32: Introduction To Web Application Testing

Ready? Let’s Go!

• Ynon Perek

• http://ynonperek.com

[email protected]