SlideShare a Scribd company logo
JavaScript Unit Testing Tools of the trade
Christian Johansen http://cjohansen.no/en http://twitter.com/cjno http://gitorious.org/~cjohansen http://github.com/cjohansen
Table of Contents Why unit test JavaScript? How to unit test JavaScript? Brief example of unit testing chat client
Why unit test JavaScript?
Debugging
 
console.log
 
 
F5, F5, F5
 
 
 
 
 
 
 
Which version? IE: 6, 7, 8 ? Firefox: 3.0, 3.5, 3.6, 3.7 ? Safari: 4, 3.1? Opera 10.50, 10.10, 10.0?
What about mobile?
Manual testing It doesn't scale
Manual testing Non reproducible
Manual testing It's time consuming
Automated unit tests
Unit tests Run now, run later Run in new browsers Put the test in a file rather than Firebug
How to unit test JavaScript? In-browser test frameworks Headless test frameworks Hybrids
In-Browser Frameworks
YUI Test Part of the YUI Framework Can test any code Typical in-browser test framework http://developer.yahoo.com/yui/3/test/
YUI Test 2
YUI Test 3
HTML Fixture loads test
Code To Test: strftime
strftime Overview
Date formats
Unit Test (YUI 3)
The Good Parts Run in any browser Simple to get started (don't even have to download YUI) Many high-level assertions
The Bad Parts Requires HTML fixture Requires internet connection (can be fixed) Does not solve the scaling problem
Similar offerings QUnit http://docs.jquery.com/QUnit JsUnitTest (Prototype.js) http://jsunittest.com/ JsUnit (Since 2001) http://jsunit.net/
Headless frameworks
JSpec BDD style testing framework Custom grammar (Ruby-like, optional) Run in browser, or headlessly http://visionmedia.github.com/jspec /
HTML Fixture
JSpec Spec
Run From Command Line
Result
Headless Run
The Good Parts Rich library of matchers Runs in browsers, Rhino, Node.js
More Good Parts Command Line Tool Initialize projects Run tests Install libraries +++
JSpec Goodness Built-in stub and mock API Built-in mock XMLHttpRequest Built-in mock timers
The Bad Parts Rhino + env.js = Fully emulated Browser launching still manual Ruby-like DSL (although optional)
Hybrids
JsTestDriver
The JsTestDriver Way Tests execute in browsers Browsers listen for tests Browsers can run locally or remote Execute in multiple browsers simultaneously
Running Tests Issue test runs from command line ...or from IDE (Eclipse + Idea) View results in command line, IDE
JsTestDriver Server java -jar JsTestDriver-1.2.jar --port 4224
 
 
 
 
JsTestDriver Config
JsTestDriver Test
Run From Command Line
100% More Color
Uh-oh!
Run in Eclipse
The Good Parts Scales! Test any platform from your machine FAST
More Good Parts Can integrate runner with other assertion frameworks (QUnit, YIU Test++) Coverage tool JUnit compatible XML output
Continuous Integration
JUnit XML Output
Hudson
 
 
Mocks and Stubs Working on it! http://gitorious.org/sinon
Quick Live Demo
Want More? Out Fall 2010 Rough cuts available: http://my.safaribooksonline.com/9780321684097
That's it! http://cjohansen.no/en http://twitter.com/cjno http://gitorious.org/~cjohansen http://github.com/cjohansen
Ad

More Related Content

What's hot (20)

Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
Hazem Saleh
 
Building testable chrome extensions
Building testable chrome extensionsBuilding testable chrome extensions
Building testable chrome extensions
Seth McLaughlin
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
Dev9Com
 
Automated Testing using JavaScript
Automated Testing using JavaScriptAutomated Testing using JavaScript
Automated Testing using JavaScript
Simon Guest
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)
Christian Johansen
 
Test your Javascript! v1.1
Test your Javascript! v1.1Test your Javascript! v1.1
Test your Javascript! v1.1
Eric Wendelin
 
Protractor for angularJS
Protractor for angularJSProtractor for angularJS
Protractor for angularJS
Krishna Kumar
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
Test automation with php codeception
Test automation with php codeceptionTest automation with php codeception
Test automation with php codeception
buddhieash
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
Luís Bastião Silva
 
Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)
Engineor
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
Albert Rosa
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
László Andrási
 
CodeIgniter Ant Scripting
CodeIgniter Ant ScriptingCodeIgniter Ant Scripting
CodeIgniter Ant Scripting
Albert Rosa
 
Automated testing in Drupal
Automated testing in DrupalAutomated testing in Drupal
Automated testing in Drupal
Artem Berdishev
 
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
UI Testing Automation - Alex Kalinovsky - CreamTec LLCUI Testing Automation - Alex Kalinovsky - CreamTec LLC
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
Jim Lane
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
Jay Friendly
 
Meetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React TestingMeetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React Testing
Augusto Lazaro
 
Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Xdebug and Drupal8 tests (PhpUnit and Simpletest)Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Francisco José Seva Mora
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
Hazem Saleh
 
Building testable chrome extensions
Building testable chrome extensionsBuilding testable chrome extensions
Building testable chrome extensions
Seth McLaughlin
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
Dev9Com
 
Automated Testing using JavaScript
Automated Testing using JavaScriptAutomated Testing using JavaScript
Automated Testing using JavaScript
Simon Guest
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)
Christian Johansen
 
Test your Javascript! v1.1
Test your Javascript! v1.1Test your Javascript! v1.1
Test your Javascript! v1.1
Eric Wendelin
 
Protractor for angularJS
Protractor for angularJSProtractor for angularJS
Protractor for angularJS
Krishna Kumar
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
Test automation with php codeception
Test automation with php codeceptionTest automation with php codeception
Test automation with php codeception
buddhieash
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
Luís Bastião Silva
 
Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)
Engineor
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
Albert Rosa
 
CodeIgniter Ant Scripting
CodeIgniter Ant ScriptingCodeIgniter Ant Scripting
CodeIgniter Ant Scripting
Albert Rosa
 
Automated testing in Drupal
Automated testing in DrupalAutomated testing in Drupal
Automated testing in Drupal
Artem Berdishev
 
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
UI Testing Automation - Alex Kalinovsky - CreamTec LLCUI Testing Automation - Alex Kalinovsky - CreamTec LLC
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
Jim Lane
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
Jay Friendly
 
Meetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React TestingMeetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React Testing
Augusto Lazaro
 
Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Xdebug and Drupal8 tests (PhpUnit and Simpletest)Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Francisco José Seva Mora
 

Viewers also liked (7)

PIano Integrato Politiche Familiari
PIano Integrato Politiche FamiliariPIano Integrato Politiche Familiari
PIano Integrato Politiche Familiari
davidenigro
 
080906 Apiq Matematika Kreatif Share
080906 Apiq Matematika Kreatif Share080906 Apiq Matematika Kreatif Share
080906 Apiq Matematika Kreatif Share
Agus Nggermanto
 
Vessier's NURS 4113 course
Vessier's NURS 4113 courseVessier's NURS 4113 course
Vessier's NURS 4113 course
Amanda Lemon
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
Srdjan Strbanovic
 
Selling sustainability-from-inside-full-report1
Selling sustainability-from-inside-full-report1Selling sustainability-from-inside-full-report1
Selling sustainability-from-inside-full-report1
Don Carli
 
SECU4 SA - Switzerland
SECU4 SA - SwitzerlandSECU4 SA - Switzerland
SECU4 SA - Switzerland
SECU4 SA
 
Bedre tilgjengelighet med HTML og CSS
Bedre tilgjengelighet med HTML og CSSBedre tilgjengelighet med HTML og CSS
Bedre tilgjengelighet med HTML og CSS
Christian Johansen
 
PIano Integrato Politiche Familiari
PIano Integrato Politiche FamiliariPIano Integrato Politiche Familiari
PIano Integrato Politiche Familiari
davidenigro
 
080906 Apiq Matematika Kreatif Share
080906 Apiq Matematika Kreatif Share080906 Apiq Matematika Kreatif Share
080906 Apiq Matematika Kreatif Share
Agus Nggermanto
 
Vessier's NURS 4113 course
Vessier's NURS 4113 courseVessier's NURS 4113 course
Vessier's NURS 4113 course
Amanda Lemon
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
Srdjan Strbanovic
 
Selling sustainability-from-inside-full-report1
Selling sustainability-from-inside-full-report1Selling sustainability-from-inside-full-report1
Selling sustainability-from-inside-full-report1
Don Carli
 
SECU4 SA - Switzerland
SECU4 SA - SwitzerlandSECU4 SA - Switzerland
SECU4 SA - Switzerland
SECU4 SA
 
Bedre tilgjengelighet med HTML og CSS
Bedre tilgjengelighet med HTML og CSSBedre tilgjengelighet med HTML og CSS
Bedre tilgjengelighet med HTML og CSS
Christian Johansen
 
Ad

Similar to JavaScript Unit Testing (20)

Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With Selenium
Jodie Miners
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
Seth McLaughlin
 
Testing Toolbox
Testing ToolboxTesting Toolbox
Testing Toolbox
Michael Peters
 
Web Test Automation Framework - IndicThreads Conference
Web Test Automation Framework  - IndicThreads ConferenceWeb Test Automation Framework  - IndicThreads Conference
Web Test Automation Framework - IndicThreads Conference
IndicThreads
 
Stepin evening presented
Stepin evening presentedStepin evening presented
Stepin evening presented
Vijayan Reddy
 
Passing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldPassing The Joel Test In The PHP World
Passing The Joel Test In The PHP World
Lorna Mitchell
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016
Yves Hoppe
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
Simon Guest
 
Selenium
SeleniumSelenium
Selenium
BugRaptors
 
Functional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with FrankensteinFunctional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with Frankenstein
vivek_prahlad
 
[DevDay 2017] Automation Testing - Speaker: Nghia Khuong - Project Manager at...
[DevDay 2017] Automation Testing - Speaker: Nghia Khuong - Project Manager at...[DevDay 2017] Automation Testing - Speaker: Nghia Khuong - Project Manager at...
[DevDay 2017] Automation Testing - Speaker: Nghia Khuong - Project Manager at...
DevDay Da Nang
 
Building JBoss AS 7 for Fedora
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedora
wolfc71
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
Nick Belhomme
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Puneet Kala
 
Selenium Introduction
Selenium IntroductionSelenium Introduction
Selenium Introduction
Mayur Khairnar
 
Selenium2 and Jenkins: Almost pain-free UI Testing
Selenium2 and Jenkins: Almost pain-free UI TestingSelenium2 and Jenkins: Almost pain-free UI Testing
Selenium2 and Jenkins: Almost pain-free UI Testing
mikereedell
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With Selenium
Marakana Inc.
 
Selenium (1)
Selenium (1)Selenium (1)
Selenium (1)
onlinemindq
 
Selenium
SeleniumSelenium
Selenium
conect2krish
 
Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With Selenium
Jodie Miners
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
Seth McLaughlin
 
Web Test Automation Framework - IndicThreads Conference
Web Test Automation Framework  - IndicThreads ConferenceWeb Test Automation Framework  - IndicThreads Conference
Web Test Automation Framework - IndicThreads Conference
IndicThreads
 
Stepin evening presented
Stepin evening presentedStepin evening presented
Stepin evening presented
Vijayan Reddy
 
Passing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldPassing The Joel Test In The PHP World
Passing The Joel Test In The PHP World
Lorna Mitchell
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016
Yves Hoppe
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
Simon Guest
 
Functional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with FrankensteinFunctional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with Frankenstein
vivek_prahlad
 
[DevDay 2017] Automation Testing - Speaker: Nghia Khuong - Project Manager at...
[DevDay 2017] Automation Testing - Speaker: Nghia Khuong - Project Manager at...[DevDay 2017] Automation Testing - Speaker: Nghia Khuong - Project Manager at...
[DevDay 2017] Automation Testing - Speaker: Nghia Khuong - Project Manager at...
DevDay Da Nang
 
Building JBoss AS 7 for Fedora
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedora
wolfc71
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
Nick Belhomme
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Puneet Kala
 
Selenium2 and Jenkins: Almost pain-free UI Testing
Selenium2 and Jenkins: Almost pain-free UI TestingSelenium2 and Jenkins: Almost pain-free UI Testing
Selenium2 and Jenkins: Almost pain-free UI Testing
mikereedell
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With Selenium
Marakana Inc.
 
Ad

JavaScript Unit Testing