Javascript Unit Testing
Upcoming SlideShare
Loading in...5
×
 

Javascript Unit Testing

on

  • 2,177 views

These are the slides I presented at the PHPBenelux 2012 conference.

These are the slides I presented at the PHPBenelux 2012 conference.

Statistics

Views

Total Views
2,177
Views on SlideShare
2,175
Embed Views
2

Actions

Likes
2
Downloads
22
Comments
0

1 Embed 2

http://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Javascript Unit Testing Javascript Unit Testing Presentation Transcript

  • Javascript Unit TestingIntroduction to QUnit & JsTestDriver
  • Tom Van HerreweghePHP developerZCE 5.0 & 5.3I like Javascripthttp://blog.theanalogguy.be@miljar
  • OverviewJavascript Unit Testing?Introduction to QUnitIntroduction to JsTestDriver
  • Javascript Unit Testing
  • JS Unit TestingNot functional testing Selenium, WatirExample: http://www.cuttherope.ie
  • JS Unit TestingMultitier ArchitectureWrite DRY codeAvoid event-coupling through HTML do it in the business logic
  • QUnit
  • QUnitJS Unit Testing libraryJQueryhttp://docs.jquery.com/Qunit
  • QUnitTestrunner = browser
  • QUnit setup Demo
  • QUnit structuremodule(‘name’[, {lifecycle}])
  • QUnit structuretest(‘name’[, expected], test-code)
  • QUnit structure Demo
  • QUnit assertionsok(state[, ‘message’])
  • QUnit assertionsequal(actual, expected[, ‘message’]) corresponds with: ==
  • QUnit assertionsstrictEqual(actual, expected[, ‘message’])
  • QUnit assertionsnotEqual(actual, expected[, ‘message’]) corresponds with: !=
  • QUnit assertions Demo
  • QUnit assertionsdeepEqual(actual, expected[, ‘message’]) corresponds with: === (recursive)
  • QUnit assertionsnotDeepEqual(actual, expected[, ‘message’]) corresponds with: !== (recursive)
  • QUnit assertions Demo
  • QUnit assertionsraises(function[, expected][, ‘message’])
  • QUnit assertions Demo
  • Async testingthe good: callbacksthe bad: timersthe ugly: currently not in QUnitAdapter forJsTestDriver
  • Async testing Timers: hard to predictrunning time + slows down
  • Async testingCallbacks: run assertions
  • Async testingCurrently not supported in QUnitAdapter
  • Async testingstop()start()expect()asyncTest()
  • Async testing Demo
  • PHPUnit QUnitPHPUnit_Framework_TestCase module test* methods test assertTrue() ok() equal() assertEquals() deepEqual() assertSame() strictEqual() notEqual() assertNotEquals() notDeepEqual()setExpectedException raises()
  • JsTestDriver
  • JsTestDriverTestrunner for your Unit TestsWritten in JavaClient / Server architecturehttp://code.google.com/p/js-test-driver
  • JsTestDriver
  • JsTestDriverCustom unit testing syntaxNeed mapping from QUnit to JsTestDriverSome QUnit functionalities not (yet) available
  • JsTestDrivermodule()test()ok()equals()same() (old name for deepEqual())
  • JsTestDriver Fetch JAR fromhttp://code.google.com/p/js-test-driver/downloads/list
  • JsTestDriver Run serverjava -jar /path/to/JsTestDriver-1.3.2.jar --port 4224
  • JsTestDriverPoint browser(s) to http://localhost:4224
  • JsTestDriver Demo
  • JsTestDriver Download QUnit adapterhttp://code.google.com/p/js-test-driver/wiki/ QUnitAdapter
  • JsTestDriver Create config
  • JsTestDriver Run testsjava -jar /path/to/JsTestDriver-1.3.2.jar --config /path/to/jsTestDriver.conf --tests all
  • JsTestDriver Demo
  • Questions?Read more?Joind.inhttps://joind.in/4777Githubhttps://github.com/Miljar/
  • Code Coverage
  • Code Coverage Download plugin fromhttp://code.google.com/p/js-test-driver/downloads/list
  • Code CoverageInclude plugin in config
  • Code CoverageAdd flags when executing tests --testOutput /path/to/outputfolder
  • Code Coverage Install LCOV
  • Code Coverage Generate HTMLgenhtml /path/to/jsTestDriver.conf-coverage.dat
  • Code Coverage Demo
  • Some linksQUnithttp://docs.jquery.com/QunitJsTestDriverhttp://code.google.com/p/js-test-driver/CI with JsTestDriverhttp://j.mp/acO6QI
  • CopyrightsBen 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/)