SlideShare a Scribd company logo
Javascript Unit
   Testing
Introduction to QUnit & JsTestDriver
Tom Van Herreweghe

PHP developer

ZCE 5.0 & 5.3

I like Javascript

http://blog.theanalogguy.be

@miljar
Overview


Javascript Unit Testing?

Introduction to QUnit

Introduction to JsTestDriver
Javascript Unit
   Testing
JS Unit Testing


Not functional testing

  Selenium, Watir

Example: http://www.cuttherope.ie
JS Unit Testing

Multitier Architecture

Write DRY code

Avoid event-coupling through HTML

  do it in the business logic
QUnit
QUnit


JS Unit Testing library

JQuery

http://docs.jquery.com/Qunit
QUnit


Testrunner = browser
QUnit setup


  Demo
QUnit structure


module(‘name’[, {lifecycle}])
QUnit structure


test(‘name’[, expected], test-code)
QUnit structure


    Demo
QUnit assertions


ok(state[, ‘message’])
QUnit assertions


equal(actual, expected[, ‘message’])




           corresponds with: ==
QUnit assertions


strictEqual(actual, expected[,
         ‘message’])
QUnit assertions

notEqual(actual, expected[,
       ‘message’])



       corresponds with: !=
QUnit assertions


     Demo
QUnit assertions

deepEqual(actual, expected[,
       ‘message’])



    corresponds with: === (recursive)
QUnit assertions

notDeepEqual(actual, expected[,
         ‘message’])



      corresponds with: !== (recursive)
QUnit assertions


     Demo
QUnit assertions

raises(function[, expected][,
         ‘message’])
QUnit assertions


     Demo
Async testing

the good: callbacks

the bad: timers

the ugly: currently not in QUnitAdapter for
JsTestDriver
Async testing

  Timers: hard to predict
running time + slows down
Async testing


Callbacks: run assertions
Async testing

Currently not supported
   in QUnitAdapter
Async testing

stop()

start()

expect()

asyncTest()
Async testing


   Demo
PHPUnit                    QUnit
PHPUnit_Framework_TestCase       module
    test* methods                  test
     assertTrue()                  ok()
                                 equal()
    assertEquals()
                              deepEqual()
    assertSame()              strictEqual()
                               notEqual()
 assertNotEquals()
                             notDeepEqual()
setExpectedException            raises()
JsTestDriver
JsTestDriver

Testrunner for your Unit Tests

Written in Java

Client / Server architecture

http://code.google.com/p/js-test-driver
JsTestDriver
JsTestDriver


Custom unit testing syntax

Need mapping from QUnit to JsTestDriver

Some QUnit functionalities not (yet) available
JsTestDriver

module()

test()

ok()

equals()

same() (old name for deepEqual())
JsTestDriver


            Fetch JAR from
http://code.google.com/p/js-test-driver/downloads/list
JsTestDriver


                 Run server
java -jar /path/to/JsTestDriver-1.3.2.jar --port 4224
JsTestDriver


Point browser(s) to
  http://localhost:4224
JsTestDriver


   Demo
JsTestDriver

   Download QUnit adapter
http://code.google.com/p/js-test-driver/wiki/
               QUnitAdapter
JsTestDriver


 Create config
JsTestDriver

                Run tests
java -jar /path/to/JsTestDriver-1.3.2.jar --config
      /path/to/jsTestDriver.conf --tests all
JsTestDriver


   Demo
Questions?

Read more?


Joind.in
https://joind.in/4777

Github
https://github.com/Miljar/
Code Coverage
Code Coverage


     Download plugin from
http://code.google.com/p/js-test-driver/downloads/list
Code Coverage


Include plugin in config
Code Coverage


Add flags when executing tests
      --testOutput /path/to/outputfolder
Code Coverage


 Install LCOV
Code Coverage


        Generate HTML
genhtml /path/to/jsTestDriver.conf-coverage.dat
Code Coverage


    Demo
Some links

QUnit
http://docs.jquery.com/Qunit

JsTestDriver
http://code.google.com/p/js-test-driver/

CI with JsTestDriver
http://j.mp/acO6QI
Copyrights


Ben Scholzen (http://www.flickr.com/photos/dasprid/5142854471/in/
set-72157625158543743)

JsTestDriver schema (http://code.google.com/p/js-test-driver/)

Christian Johansen (http://cjohansen.no/)

More Related Content

PDF
Painless JavaScript Testing with Jest
PDF
Testing javascript in the frontend
PPT
jUnit
PDF
Unit Testing with Jest
PDF
Unit Testing - The Whys, Whens and Hows
PPTX
Understanding JavaScript Testing
PDF
Testacular
PDF
AngularJS Unit Testing w/Karma and Jasmine
Painless JavaScript Testing with Jest
Testing javascript in the frontend
jUnit
Unit Testing with Jest
Unit Testing - The Whys, Whens and Hows
Understanding JavaScript Testing
Testacular
AngularJS Unit Testing w/Karma and Jasmine

What's hot (20)

PDF
Understanding JavaScript Testing
PDF
Angular testing
PDF
Javascript tdd byandreapaciolla
PDF
Сергей Больщиков "Protractor Tips & Tricks"
PDF
JavaScript TDD with Jasmine and Karma
PPTX
Qunit Java script Un
PPT
JavaScript Unit Testing
PDF
JavaFX8 TestFX - CDI
PPTX
Unit testing on mobile apps
PDF
Intro to Unit Testing in AngularJS
PPTX
Testing with VS2010 - A Bugs Life
PPT
JavaScript Unit Testing
PDF
おっぴろげJavaEE DevOps
PPTX
Automation testing with Drupal 8
PDF
Advanced Jasmine - Front-End JavaScript Unit Testing
PDF
Quick tour to front end unit testing using jasmine
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
PDF
Unit-testing and E2E testing in JS
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
PDF
Efficient JavaScript Unit Testing, May 2012
Understanding JavaScript Testing
Angular testing
Javascript tdd byandreapaciolla
Сергей Больщиков "Protractor Tips & Tricks"
JavaScript TDD with Jasmine and Karma
Qunit Java script Un
JavaScript Unit Testing
JavaFX8 TestFX - CDI
Unit testing on mobile apps
Intro to Unit Testing in AngularJS
Testing with VS2010 - A Bugs Life
JavaScript Unit Testing
おっぴろげJavaEE DevOps
Automation testing with Drupal 8
Advanced Jasmine - Front-End JavaScript Unit Testing
Quick tour to front end unit testing using jasmine
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit-testing and E2E testing in JS
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Efficient JavaScript Unit Testing, May 2012
Ad

Similar to Javascript Unit Testing (20)

PDF
Javascript Unit Testting (PHPBenelux 2011-05-04)
PDF
Introduction to Unit Testing using QUnit
PDF
Front-End Testing: Demystified
PPTX
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
 
PDF
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
PDF
Adventures In JavaScript Testing
PDF
Efficient JavaScript Unit Testing, March 2013
PDF
Qunit tutorial
PDF
Thomas Fuchs Presentation
PPTX
Tests in Javascript using Jasmine and Testacular
PDF
Testing, Performance Analysis, and jQuery 1.4
PDF
3 WAYS TO TEST YOUR COLDFUSION API
PDF
3 WAYS TO TEST YOUR COLDFUSION API -
PDF
Javascript unit testing with QUnit and Sinon
PDF
Automated Web Testing using JavaScript
PDF
PPTX
Qt test framework
 
PDF
Unit testing [4] - Software Testing Techniques (CIS640)
PPTX
Unit Testing TypeScript
PDF
Javascript Unit Testing Tools
Javascript Unit Testting (PHPBenelux 2011-05-04)
Introduction to Unit Testing using QUnit
Front-End Testing: Demystified
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
Adventures In JavaScript Testing
Efficient JavaScript Unit Testing, March 2013
Qunit tutorial
Thomas Fuchs Presentation
Tests in Javascript using Jasmine and Testacular
Testing, Performance Analysis, and jQuery 1.4
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API -
Javascript unit testing with QUnit and Sinon
Automated Web Testing using JavaScript
Qt test framework
 
Unit testing [4] - Software Testing Techniques (CIS640)
Unit Testing TypeScript
Javascript Unit Testing Tools
Ad

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
KodekX | Application Modernization Development
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
cuic standard and advanced reporting.pdf
Spectroscopy.pptx food analysis technology
Big Data Technologies - Introduction.pptx
KodekX | Application Modernization Development
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Network Security Unit 5.pdf for BCA BBA.
MIND Revenue Release Quarter 2 2025 Press Release
sap open course for s4hana steps from ECC to s4
Advanced methodologies resolving dimensionality complications for autism neur...

Javascript Unit Testing