Understanding JavaScript Testing

jeresig
JavaScript Testing
                 John Resig
http://ejohn.org/ - http://twitter.com/jeresig
Why Test JavaScript?
✦   Cross-browser issues.
✦   The possibility for causing an unforeseen
    problem is simply too great.
What should I use?
Looong Tail

250.0


187.5


125.0


 62.5


   0


               Other
People don’t test. :-(

900


675


450


225


  0


                         None
Basic Components
✦   Writing and understanding a JavaScript
    test suite is easy.
✦   Test Suite
    ✦ Tests
      ✦ Assertions
    ✦ Async Tests

✦   Test Runner
Assertions
   <html> 
   <head> 
     <title>Test Suite</title> 
     <script> 
     function assert( value, desc ) { 
       var li = document.createElement("li"); 
       li.className = value ? "pass" : "fail"; 
       li.appendChild( document.createTextNode( desc ) ); 
       document.getElementById("results").appendChild( li ); 
     } 
                                    
     window.onload = function(){ 
       assert( true, "The test suite is running." ); 
     }; 
     </script> 
     <style> 
       #results li.pass { color: green; } 
       #results li.fail { color: red; } 
     </style> 
   </head> 
   <body> 
     <ul id="results"></ul> 
   </body> 
   </html> 
Tests
      test("A test.", function(){ 
        assert( true, "First assertion completed" ); 
        assert( true, "Second assertion completed" ); 
        assert( true, "Third assertion completed" ); 
      }); 
                                  
      test("Another test.", function(){ 
        assert( true, "First test completed" ); 
        assert( false, "Second test failed" ); 
        assert( true, "Third assertion completed" ); 
      }); 
Tests
    var results; 
                                  
    function assert( value, desc ) { 
      var li = document.createElement("li"); 
      li.className = value ? "pass" : "fail"; 
      li.appendChild( document.createTextNode( desc ) ); 
      results.appendChild( li ); 
      if ( !value ) { 
        li.parentNode.parentNode.className = "fail"; 
      } 
      return li; 
    } 
                                  
    function test(name, fn){ 
      results = document.getElementById("results"); 
      results = assert( true, name ).appendChild( 
        document.createElement("ul") ); 
      fn(); 
    } 
Async Tests
    test(function(){ 
      pause(); 
      setTimeout(function(){ 
        assert( true, "First test completed" ); 
        resume(); 
      }, 100); 
    }); 
                            
    test(function(){ 
      pause(); 
      setTimeout(function(){ 
        assert( true, "Second test completed" ); 
        resume(); 
      }, 200); 
    }); 
Async Tests
      (function(){ 
        var queue = [], paused = false; 
                             
        this.test = function(fn){ 
          queue.push( fn ); 
          runTest(); 
        }; 
                             
        this.pause = function(){ 
          paused = true; 
        }; 
                             
        this.resume = function(){ 
          paused = false; 
          setTimeout(runTest, 1); 
        }; 
                             
        function runTest(){ 
          if ( !paused && queue.length ) { 
            queue.shift()(); 
            if ( !paused ) { 
              resume(); 
            } 
          } 
        } 
      })(); 
TestRunner
✦   Responsible for loading an executing tests.
✦   Sometimes individual test groups can run
    standalone (Dojo) sometimes they require
    the test runner (QUnit, JSUnit).
Popular Test Frameworks

250.0


187.5


125.0


 62.5


   0
        QUnit   JSUnit   Selenium YUITest FireUnit Screw.Unit JSSpec
Unit Testing
✦   Break code into logical chucks for testing.
✦   Focus on one method at a time.
✦   Popular Frameworks:
    ✦ QUnit
    ✦ JSUnit
    ✦ YUITest
QUnit
✦   Unit Testing framework built for jQuery.
✦   Additional features:
    ✦ Supports asynchronous testing.
    ✦ Can break code into modules.
    ✦ Supports test timeouts.

✦   http://docs.jquery.com/QUnit
QUnit Style
   test("a basic test example", function() { 
     ok( true, "this test is fine" ); 
     var value = "hello"; 
     equals( "hello", value, "We expect value to be hello" ); 
   }); 
                                  
   module("Module A"); 
                                  
   test("first test within module", function() { 
     ok( true, "all pass" ); 
   }); 
                                  
   test("second test within module", function() { 
     ok( true, "all pass" ); 
   }); 
                                  
   module("Module B"); 
                                  
   test("some other test", function() { 
     expect(2); 
     equals( true, false, "failing test" ); 
     equals( true, true, "passing test" ); 
   }); 
QUnit
JSUnit
✦   One of the oldest JavaScript testing
    frameworks.
✦   A port of JUnit to JavaScript, circa 2001.
✦   Code feels very 2001 (frames!)
✦   http://www.jsunit.net/
JSUnit
        function coreSuite() { 
            var result = new top.jsUnitTestSuite(); 
            result.addTestPage("tests/jsUnitAssertionTests.html"); 
            result.addTestPage("tests/jsUnitSetUpTearDownTests.html"); 
            result.addTestPage("tests/jsUnitRestoredHTMLDivTests.html"); 
            result.addTestPage("tests/jsUnitFrameworkUtilityTests.html"); 
            result.addTestPage("tests/jsUnitOnLoadTests.html"); 
            result.addTestPage("tests/jsUnitUtilityTests.html"); 
            return result; 
        } 
                                               
        function serverSuite() { 
            var result = new top.jsUnitTestSuite(); 
            result.addTestPage("tests/server/jsUnitVersionCheckTests.html"); 
            result.addTestPage("tests/server/jsUnitServerAjaxTests.html"); 
            return result; 
        } 
                                               
        function librariesSuite() { 
            var result = new top.jsUnitTestSuite(); 
            result.addTestPage("tests/jsUnitMockTimeoutTest.html"); 
            return result; 
        } 
                                               
        function suite() { 
            var newsuite = new top.jsUnitTestSuite(); 
            newsuite.addTestSuite(coreSuite()); 
            newsuite.addTestSuite(serverSuite()); 
            newsuite.addTestSuite(librariesSuite()); 
            return newsuite; 
        }
JSUnit
   function testAssertNotUndefined() { 
       assertNotUndefined("1 should not be undefined", 1); 
       assertNotUndefined(1); 
   } 
                                             
   function testAssertNaN() { 
       assertNaN("a string should not be a number", "string"); 
       assertNaN("string"); 
   } 
                                             
   function testAssertNotNaN() { 
       assertNotNaN("1 should not be not a number", 1); 
       assertNotNaN(1); 
   } 
                                             
   function testFail() { 
       var excep = null; 
       try { 
           fail("Failure message"); 
       } catch (e) { 
           excep = e; 
       } 
       assertJsUnitException("fail(string) should throw a JsUnitException", excep); 
   } 
                                             
   function testTooFewArguments() { 
       var excep = null; 
       try { 
           assert(); 
       } catch (e1) { 
           excep = e1; 
       } 
       assertNonJsUnitException("Calling an assertion function with too 
         few arguments should throw an exception", excep); 
   }
JSUnit
YUITest (2 & 3)
✦   Testing framework built and developed by
    Yahoo (released Oct 2008).
✦   Completely overhauled to go with YUI v3.
✦   Features:
    ✦ Supports async tests.
    ✦ Has good event simulation.

✦   v2: http://developer.yahoo.com/yui/
    examples/yuitest/
✦   v3: http://developer.yahoo.com/yui/3/test/
YUITest 2
   YAHOO.example.yuitest.ArrayTestCase = new YAHOO.tool.TestCase({ 
      name : "Array Tests", 
                                         
      setUp : function () { 
          this.data = [0,1,2,3,4] 
      }, 
                                         
      tearDown : function () { 
          delete this.data; 
      }, 
                                           
      testPop : function () { 
          var Assert = YAHOO.util.Assert;          
          var value = this.data.pop(); 
                                             
          Assert.areEqual(4, this.data.length); 
          Assert.areEqual(4, value);             
      },         
                                         
      testPush : function () { 
          var Assert = YAHOO.util.Assert; 
                                             
          this.data.push(5); 
                                             
          Assert.areEqual(6, this.data.length); 
          Assert.areEqual(5, this.data[5]);             
      }
  }); 
YUITest 2
YUITest 3
    Y.example.test.DataTestCase = new Y.Test.Case({ 
        name : "Data Tests", 
                                        
        setUp : function () { 
            this.data = { 
                name: "test", 
                year: 2007, 
                beta: true 
            }; 
        }, 
         
        tearDown : function () { 
            delete this.data; 
        }, 
                                        
        testName : function () { 
            var Assert = Y.Assert; 
                                            
            Assert.isObject(this.data); 
            Assert.isString(this.data.name); 
            Assert.areEqual("test", this.data.name);             
        }, 
                                        
        testYear : function () { 
            var Assert = Y.Assert; 
                                            
            Assert.isObject(this.data); 
            Assert.isNumber(this.data.year); 
            Assert.areEqual(2007, this.data.year);             
        }
    }); 
YUITest 3
Behavior Testing
✦   Similar to unit testing, but broken up by
    task.
✦   Functionally very similar to unit testing,
    uses different terminology
✦   Popular frameworks:
    ✦ Screw.Unit
    ✦ JSSpec
Screw.Unit
✦   Popular BDD framework.
✦   http://github.com/nathansobo/screw-unit/
    tree/master
Screw.Unit
 describe("a nested describe", function() { 
   var invocations = []; 
                                     
   before(function() { 
     invocations.push("before"); 
   }); 
                                     
   describe("a doubly nested describe", function() { 
     before(function() { 
       invocations.push('inner before'); 
     }); 
                                     
     it("runs befores in all ancestors prior to an it", function() { 
       expect(invocations).to(equal, ["before", "inner before"]); 
     }); 
   }); 
 }); 
Screw.Unit
JSSpec
✦   Used by MooTools as their testing
    framework.
✦   http://jania.pe.kr/aw/moin.cgi/JSSpec
JSSpec
   describe('"Should have"s', { 
     'String length': function() { 
       expect("Hello").should_have(4, "characters"); 
     }, 
     'Array length': function() { 
       expect([1,2,3]).should_have(4, "items"); 
     }, 
     'Object's item length': function() { 
       expect({name:'Alan Kang', email:'jania902@gmail.com',
         accounts:['A', 'B']}).should_have(3, "accounts"); 
     }, 
     'No match': function() { 
       expect("This is a string").should_have(5, "players"); 
     }, 
     'Exactly': function() { 
       expect([1,2,3]).should_have_exactly(2, "items"); 
     }, 
     'At least': function() { 
       expect([1,2,3]).should_have_at_least(4, "items"); 
     }, 
     'At most': function() { 
       expect([1,2,3]).should_have_at_most(2, "items"); 
     } 
   }) 
JSSpec
Automation
✦   Functional Testing
✦   Browser launching
✦   Server-Side
Functional Testing
✦   Selenium IDE
✦   There may be others by Selenium is far
    and away the best.
Selenium IDE
✦   Records and automates actions performed
    by a user.
✦   An extension for Firefox that records the
    actions.
✦   Can play them back in all browsers
    (limited by cross-domain issues).
✦   Primarily for testing web applications -
    everyone should use it, though!
✦   http://seleniumhq.org/projects/ide/
Selenium IDE
Browser Launching
✦   Automates the process of opening browser
    windows, running tests, and getting results.
✦   Frequently require a specific framework.
✦   Popular frameworks:
    ✦ WebDriver http://code.google.com/p/
      webdriver/ (Java)
    ✦ Waitr http://wtr.rubyforge.org/ (Ruby)
    ✦ JsTestDriver http://code.google.com/p/
      js-test-driver/ (Java)
    ✦ Selenium RC http://seleniumhq.org/
      projects/remote-control/ (Java)
Browser Launching
Server-Side
✦   Ignore the browser! Simulate it on the
    server-side.
✦   Almost always uses Java + Rhino to
    construct a browser.
✦   Some frameworks:
    ✦ Crosscheck
    ✦ Env.js
    ✦ Blueridge
Server-Side
✦   Crosscheck
    ✦ Pure Java, even simulates browser bugs.
    ✦ http://www.thefrontside.net/crosscheck

✦   Env.js
    ✦ Pure JavaScript, focuses on standards
      support.
    ✦ http://github.com/thatcher/env-js/tree/
      master
✦   Blueridge
    ✦ Env.js + Screw.Unit + Rhino
    ✦ http://github.com/relevance/blue-ridge/
Env.js
  $ java -jar build/js.jar
  Rhino 1.6 release 6 2007 06 28
  js> load('build/runtest/env.js');

  js> window.location = 'test/index.html';
  test/index.html

  js> load('dist/jquery.js');

  // Add pretty printing to jQuery objects:
  js> jQuery.fn.toString = DOMNodeList.prototype.toString;

  js> $('span').remove();
  [ <span#å°åŒ—Taibei>, <span#å°åŒ—>, <span#utf8class1>,
    <span#utf8class2>, <span#foo:bar>, <span#test.foo[5]bar> ]

  // Yes - UTF-8 is supported in DOM documents!
  js> $('span')
  [ ]

  js> $('div').append('<span><b>hello!</b> world</span>');
  [ <div#main>, <div#foo> ]

  js> $('span')
  [ <span>, <span> ]

  js> $('span').text()
  hello! worldhello! world
Distributed
✦   Selenium Grid
    ✦ Push Selenium tests out to many
      machines (that you manage),
      simultaneously.
    ✦ Collect and store the results.
    ✦ http://selenium-grid.seleniumhq.org/

✦   TestSwarm
    ✦ Push tests to a distributed swarm of
      clients.
    ✦ Results viewable on the server.
    ✦ http://testswarm.com/
TestSwarm
Choose Your Browsers
Cost / Benefit




  IE 7     IE 6          FF 3    Safari 3   Opera 9.5
                  Cost          Benefit


         Draw a line in the sand.
Graded Support




   Yahoo Browser Compatibility
Browser Support Grid
           IE      Firefox   Safari   Opera Chrome


Previous   6.0       2.0      3.0      9.5


Current    7.0       3.0      3.2      9.6    1.0


 Next      8.0       3.1      4.0     10.0    2.0

                 jQuery Browser Support
Browser Support Grid
           IE       Firefox   Safari   Opera Chrome


Previous   6.0        2.0      3.0      9.5


Current    7.0        3.0      3.2      9.6    1.0


 Next      8.0        3.1      4.0     10.0    2.0

                jQuery 1.3 Browser Support
The Scaling Problem
✦   The Problem:
    ✦ jQuery has 6 test suites
    ✦ Run in 11 browsers
    ✦ (Not even including multiple platforms!)

✦   All need to be run for every commit,
    patch, and plugin.
✦   JavaScript testing doesn’t scale well.
Distributed Testing
✦   Hub server
✦   Clients connect and help run tests
✦   A simple JavaScript client that can be run
    in all browsers
    ✦ Including mobile browsers!


✦ TestSwarm
FF 3.5 FF 3.5 FF 3.5
                                                  IE 6
                                                         IE 6
       FF 3                                                      IE 6
                                           Op 9
FF 3

                                                                 IE 7

                               TestSwarm
                                                                  IE 7




              Test Suite        Test Suite          Test Suite
Manual Testing
✦   Push tests to users who follow pre-defined
    steps
✦   Answer ‘Yes’/’No’ questions which are
    pushed back to the server.
✦   An effective way to distribute manual test
    load to dozens of clients.
TestSwarm.com
✦   Incentives for top testers (t-shirts, books)
✦   Will be opening for alpha testing very soon
✦   Help your favorite JavaScript library
    become better tested!
✦   http://testswarm.com
Questions
✦   Contact:
    ✦ John Resig
    ✦ http://ejohn.org/
    ✦ http://twitter.com/jeresig

✦   More info:
    ✦ http://jsninja.com/Overview
    ✦ http://ejohn.org/blog/javascript-testing-
      does-not-scale/
1 of 55

Recommended

Understanding JavaScript Testing by
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript TestingKissy Team
1.4K views46 slides
Adventures In JavaScript Testing by
Adventures In JavaScript TestingAdventures In JavaScript Testing
Adventures In JavaScript TestingThomas Fuchs
1.5K views62 slides
Testing, Performance Analysis, and jQuery 1.4 by
Testing, Performance Analysis, and jQuery 1.4Testing, Performance Analysis, and jQuery 1.4
Testing, Performance Analysis, and jQuery 1.4jeresig
12.1K views81 slides
Testing JavaScript Applications by
Testing JavaScript ApplicationsTesting JavaScript Applications
Testing JavaScript ApplicationsThe Rolling Scopes
2.2K views70 slides
Qunit Java script Un by
Qunit Java script UnQunit Java script Un
Qunit Java script Unakanksha arora
4.2K views32 slides
Stop Making Excuses and Start Testing Your JavaScript by
Stop Making Excuses and Start Testing Your JavaScriptStop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScriptRyan Anklam
7.1K views84 slides

More Related Content

What's hot

An introduction to Google test framework by
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test frameworkAbner Chih Yi Huang
9.2K views40 slides
GeeCON 2012 Bad Tests, Good Tests by
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsTomek Kaczanowski
1.1K views89 slides
Confitura 2012 Bad Tests, Good Tests by
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsTomek Kaczanowski
645 views99 slides
Unit testing in iOS featuring OCUnit, GHUnit & OCMock by
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockRobot Media
4.9K views48 slides
Testing javascript in the frontend by
Testing javascript in the frontendTesting javascript in the frontend
Testing javascript in the frontendFrederic CABASSUT
939 views57 slides
Painless JavaScript Testing with Jest by
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with JestMichał Pierzchała
4.8K views65 slides

What's hot(20)

Unit testing in iOS featuring OCUnit, GHUnit & OCMock by Robot Media
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Robot Media4.9K views
Redux for ReactJS Programmers by David Rodenas
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
David Rodenas605 views
Jasmine - why JS tests don't smell fishy by Igor Napierala
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
Igor Napierala4.7K views
Advanced Jasmine - Front-End JavaScript Unit Testing by Lars Thorup
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
Lars Thorup24.2K views
xUnit Style Database Testing by Chris Oldwood
xUnit Style Database TestingxUnit Style Database Testing
xUnit Style Database Testing
Chris Oldwood1.6K views
C++ Unit Test with Google Testing Framework by Humberto Marchezi
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing Framework
Humberto Marchezi7.4K views
Unit tests in node.js by Rotem Tamir
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
Rotem Tamir873 views
Unit testing with Easymock by Ürgo Ringo
Unit testing with EasymockUnit testing with Easymock
Unit testing with Easymock
Ürgo Ringo2.4K views

Viewers also liked

JavaScript Unit Testing by
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit TestingChristian Johansen
2.1K views30 slides
JavaScript Libraries (Ajax Exp 2006) by
JavaScript Libraries (Ajax Exp 2006)JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)jeresig
3.1K views62 slides
Processing and Processing.js by
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.jsjeresig
2.7K views15 slides
JavaScript Libraries (Kings of Code) by
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)jeresig
2.2K views83 slides
jQuery Internals + Cool Stuff by
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuffjeresig
6.1K views37 slides
Testing Mobile JavaScript (Fall 2010 by
Testing Mobile JavaScript (Fall 2010Testing Mobile JavaScript (Fall 2010
Testing Mobile JavaScript (Fall 2010jeresig
1.6K views48 slides

Viewers also liked(20)

JavaScript Libraries (Ajax Exp 2006) by jeresig
JavaScript Libraries (Ajax Exp 2006)JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)
jeresig3.1K views
Processing and Processing.js by jeresig
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.js
jeresig2.7K views
JavaScript Libraries (Kings of Code) by jeresig
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
jeresig2.2K views
jQuery Internals + Cool Stuff by jeresig
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
jeresig6.1K views
Testing Mobile JavaScript (Fall 2010 by jeresig
Testing Mobile JavaScript (Fall 2010Testing Mobile JavaScript (Fall 2010
Testing Mobile JavaScript (Fall 2010
jeresig1.6K views
Secrets of JavaScript Libraries by jeresig
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
jeresig41.5K views
Khan Academy Computer Science by jeresig
Khan Academy Computer ScienceKhan Academy Computer Science
Khan Academy Computer Science
jeresig14.3K views
Testing React Applications by stbaechler
Testing React ApplicationsTesting React Applications
Testing React Applications
stbaechler933 views
War of Attrition: AWS vs. Google, IBM and Microsoft Azure by IT Brand Pulse
War of Attrition: AWS vs. Google, IBM and Microsoft AzureWar of Attrition: AWS vs. Google, IBM and Microsoft Azure
War of Attrition: AWS vs. Google, IBM and Microsoft Azure
IT Brand Pulse7.7K views
Javascript Unit Testting (PHPBenelux 2011-05-04) by Tom Van Herreweghe
Javascript Unit Testting (PHPBenelux 2011-05-04)Javascript Unit Testting (PHPBenelux 2011-05-04)
Javascript Unit Testting (PHPBenelux 2011-05-04)
Tom Van Herreweghe1.6K views
Workshop 23: ReactJS, React & Redux testing by Visual Engineering
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering1.8K views
Advanced QUnit - Front-End JavaScript Unit Testing by Lars Thorup
Advanced QUnit - Front-End JavaScript Unit TestingAdvanced QUnit - Front-End JavaScript Unit Testing
Advanced QUnit - Front-End JavaScript Unit Testing
Lars Thorup4.5K views
Building a JavaScript Library by jeresig
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
jeresig11.7K views
JavaScript Test-Driven Development (TDD) with QUnit by Tasanakorn Phaipool
JavaScript Test-Driven Development (TDD) with QUnitJavaScript Test-Driven Development (TDD) with QUnit
JavaScript Test-Driven Development (TDD) with QUnit
Tasanakorn Phaipool3.9K views
Unit testing JavaScript using Mocha and Node by Josh Mock
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
Josh Mock11.2K views
The Many Ways to Test Your React App by All Things Open
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open2.1K views
Unit Testing in JavaScript with MVC and QUnit by Lars Thorup
Unit Testing in JavaScript with MVC and QUnitUnit Testing in JavaScript with MVC and QUnit
Unit Testing in JavaScript with MVC and QUnit
Lars Thorup4.3K views

Similar to Understanding JavaScript Testing

Js 单元测试框架介绍 by
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍louieuser
1.1K views35 slides
Unittesting JavaScript with Evidence by
Unittesting JavaScript with EvidenceUnittesting JavaScript with Evidence
Unittesting JavaScript with EvidenceTobie Langel
5.1K views110 slides
Junit 5 - Maior e melhor by
Junit 5 - Maior e melhorJunit 5 - Maior e melhor
Junit 5 - Maior e melhorTiago de Freitas Lima
352 views52 slides
How to write clean tests by
How to write clean testsHow to write clean tests
How to write clean testsDanylenko Max
55 views43 slides
TestNG vs Junit by
TestNG vs JunitTestNG vs Junit
TestNG vs JunitBüşra İçöz
188 views24 slides
3 j unit by
3 j unit3 j unit
3 j unitkishoregali
1.8K views73 slides

Similar to Understanding JavaScript Testing(20)

Js 单元测试框架介绍 by louieuser
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍
louieuser1.1K views
Unittesting JavaScript with Evidence by Tobie Langel
Unittesting JavaScript with EvidenceUnittesting JavaScript with Evidence
Unittesting JavaScript with Evidence
Tobie Langel5.1K views
Unit testing with PHPUnit by ferca_sl
Unit testing with PHPUnitUnit testing with PHPUnit
Unit testing with PHPUnit
ferca_sl2.5K views
Test driven node.js by Jay Harris
Test driven node.jsTest driven node.js
Test driven node.js
Jay Harris5.3K views
Pragmatic unittestingwithj unit by liminescence
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
liminescence324 views
Unit Testing Front End JavaScript by FITC
Unit Testing Front End JavaScriptUnit Testing Front End JavaScript
Unit Testing Front End JavaScript
FITC1.9K views
We Are All Testers Now: The Testing Pyramid and Front-End Development by All Things Open
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
All Things Open375 views

More from jeresig

Does Coding Every Day Matter? by
Does Coding Every Day Matter?Does Coding Every Day Matter?
Does Coding Every Day Matter?jeresig
3K views19 slides
Accidentally Becoming a Digital Librarian by
Accidentally Becoming a Digital LibrarianAccidentally Becoming a Digital Librarian
Accidentally Becoming a Digital Librarianjeresig
1.3K views72 slides
2014: John's Favorite Thing (Neo4j) by
2014: John's Favorite Thing (Neo4j)2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)jeresig
847 views42 slides
Computer Vision as Art Historical Investigation by
Computer Vision as Art Historical InvestigationComputer Vision as Art Historical Investigation
Computer Vision as Art Historical Investigationjeresig
1K views89 slides
Hacking Art History by
Hacking Art HistoryHacking Art History
Hacking Art Historyjeresig
925 views107 slides
Using JS to teach JS at Khan Academy by
Using JS to teach JS at Khan AcademyUsing JS to teach JS at Khan Academy
Using JS to teach JS at Khan Academyjeresig
1K views25 slides

More from jeresig(20)

Does Coding Every Day Matter? by jeresig
Does Coding Every Day Matter?Does Coding Every Day Matter?
Does Coding Every Day Matter?
jeresig3K views
Accidentally Becoming a Digital Librarian by jeresig
Accidentally Becoming a Digital LibrarianAccidentally Becoming a Digital Librarian
Accidentally Becoming a Digital Librarian
jeresig1.3K views
2014: John's Favorite Thing (Neo4j) by jeresig
2014: John's Favorite Thing (Neo4j)2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)
jeresig847 views
Computer Vision as Art Historical Investigation by jeresig
Computer Vision as Art Historical InvestigationComputer Vision as Art Historical Investigation
Computer Vision as Art Historical Investigation
jeresig1K views
Hacking Art History by jeresig
Hacking Art HistoryHacking Art History
Hacking Art History
jeresig925 views
Using JS to teach JS at Khan Academy by jeresig
Using JS to teach JS at Khan AcademyUsing JS to teach JS at Khan Academy
Using JS to teach JS at Khan Academy
jeresig1K views
Applying Computer Vision to Art History by jeresig
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art History
jeresig826 views
NYARC 2014: Frick/Zeri Results by jeresig
NYARC 2014: Frick/Zeri ResultsNYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri Results
jeresig2.1K views
EmpireJS: Hacking Art with Node js and Image Analysis by jeresig
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysis
jeresig18.5K views
Applying Computer Vision to Art History by jeresig
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art History
jeresig3.1K views
Introduction to jQuery (Ajax Exp 2006) by jeresig
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)
jeresig2.4K views
jQuery Recommendations to the W3C (2011) by jeresig
jQuery Recommendations to the W3C (2011)jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)
jeresig1.7K views
jQuery Open Source Process (RIT 2011) by jeresig
jQuery Open Source Process (RIT 2011)jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)
jeresig1.7K views
jQuery Open Source Process (Knight Foundation 2011) by jeresig
jQuery Open Source Process (Knight Foundation 2011)jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)
jeresig2.2K views
jQuery Mobile by jeresig
jQuery MobilejQuery Mobile
jQuery Mobile
jeresig1.5K views
jQuery Open Source (Fronteer 2011) by jeresig
jQuery Open Source (Fronteer 2011)jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)
jeresig4K views
Holistic JavaScript Performance by jeresig
Holistic JavaScript PerformanceHolistic JavaScript Performance
Holistic JavaScript Performance
jeresig4K views
New Features Coming in Browsers (RIT '09) by jeresig
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)
jeresig1.5K views
Introduction to jQuery (Ajax Exp 2007) by jeresig
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)
jeresig1.3K views
Advanced jQuery (Ajax Exp 2007) by jeresig
Advanced jQuery (Ajax Exp 2007)Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)
jeresig1.3K views

Recently uploaded

SAP Automation Using Bar Code and FIORI.pdf by
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdfVirendra Rai, PMP
23 views38 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 slide
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
80 views25 slides
Vertical User Stories by
Vertical User StoriesVertical User Stories
Vertical User StoriesMoisés Armani Ramírez
14 views16 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
248 views20 slides
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...Jasper Oosterveld
18 views49 slides

Recently uploaded(20)

SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10248 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely21 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software263 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views

Understanding JavaScript Testing

  • 1. JavaScript Testing John Resig http://ejohn.org/ - http://twitter.com/jeresig
  • 2. Why Test JavaScript? ✦ Cross-browser issues. ✦ The possibility for causing an unforeseen problem is simply too great.
  • 5. People don’t test. :-( 900 675 450 225 0 None
  • 6. Basic Components ✦ Writing and understanding a JavaScript test suite is easy. ✦ Test Suite ✦ Tests ✦ Assertions ✦ Async Tests ✦ Test Runner
  • 7. Assertions  <html>   <head>     <title>Test Suite</title>     <script>     function assert( value, desc ) {       var li = document.createElement("li");       li.className = value ? "pass" : "fail";       li.appendChild( document.createTextNode( desc ) );       document.getElementById("results").appendChild( li );     }          window.onload = function(){       assert( true, "The test suite is running." );     };     </script>     <style>       #results li.pass { color: green; }       #results li.fail { color: red; }     </style>   </head>   <body>     <ul id="results"></ul>   </body>   </html> 
  • 8. Tests      test("A test.", function(){         assert( true, "First assertion completed" );         assert( true, "Second assertion completed" );         assert( true, "Third assertion completed" );       });              test("Another test.", function(){         assert( true, "First test completed" );         assert( false, "Second test failed" );         assert( true, "Third assertion completed" );       }); 
  • 9. Tests    var results;          function assert( value, desc ) {       var li = document.createElement("li");       li.className = value ? "pass" : "fail";       li.appendChild( document.createTextNode( desc ) );       results.appendChild( li );       if ( !value ) {         li.parentNode.parentNode.className = "fail";       }       return li;     }          function test(name, fn){       results = document.getElementById("results");       results = assert( true, name ).appendChild(         document.createElement("ul") );       fn();     } 
  • 10. Async Tests  test(function(){     pause();     setTimeout(function(){       assert( true, "First test completed" );       resume();     }, 100);   });      test(function(){     pause();     setTimeout(function(){       assert( true, "Second test completed" );       resume();     }, 200);   }); 
  • 11. Async Tests  (function(){     var queue = [], paused = false;          this.test = function(fn){       queue.push( fn );       runTest();     };          this.pause = function(){       paused = true;     };          this.resume = function(){       paused = false;       setTimeout(runTest, 1);     };          function runTest(){       if ( !paused && queue.length ) {         queue.shift()();         if ( !paused ) {           resume();         }       }     }   })(); 
  • 12. TestRunner ✦ Responsible for loading an executing tests. ✦ Sometimes individual test groups can run standalone (Dojo) sometimes they require the test runner (QUnit, JSUnit).
  • 13. Popular Test Frameworks 250.0 187.5 125.0 62.5 0 QUnit JSUnit Selenium YUITest FireUnit Screw.Unit JSSpec
  • 14. Unit Testing ✦ Break code into logical chucks for testing. ✦ Focus on one method at a time. ✦ Popular Frameworks: ✦ QUnit ✦ JSUnit ✦ YUITest
  • 15. QUnit ✦ Unit Testing framework built for jQuery. ✦ Additional features: ✦ Supports asynchronous testing. ✦ Can break code into modules. ✦ Supports test timeouts. ✦ http://docs.jquery.com/QUnit
  • 16. QUnit Style  test("a basic test example", function() {     ok( true, "this test is fine" );     var value = "hello";     equals( "hello", value, "We expect value to be hello" );   });      module("Module A");      test("first test within module", function() {     ok( true, "all pass" );   });      test("second test within module", function() {     ok( true, "all pass" );   });      module("Module B");      test("some other test", function() {     expect(2);     equals( true, false, "failing test" );     equals( true, true, "passing test" );   }); 
  • 17. QUnit
  • 18. JSUnit ✦ One of the oldest JavaScript testing frameworks. ✦ A port of JUnit to JavaScript, circa 2001. ✦ Code feels very 2001 (frames!) ✦ http://www.jsunit.net/
  • 19. JSUnit        function coreSuite() {             var result = new top.jsUnitTestSuite();             result.addTestPage("tests/jsUnitAssertionTests.html");             result.addTestPage("tests/jsUnitSetUpTearDownTests.html");             result.addTestPage("tests/jsUnitRestoredHTMLDivTests.html");             result.addTestPage("tests/jsUnitFrameworkUtilityTests.html");             result.addTestPage("tests/jsUnitOnLoadTests.html");             result.addTestPage("tests/jsUnitUtilityTests.html");             return result;         }                  function serverSuite() {             var result = new top.jsUnitTestSuite();             result.addTestPage("tests/server/jsUnitVersionCheckTests.html");             result.addTestPage("tests/server/jsUnitServerAjaxTests.html");             return result;         }                  function librariesSuite() {             var result = new top.jsUnitTestSuite();             result.addTestPage("tests/jsUnitMockTimeoutTest.html");             return result;         }                  function suite() {             var newsuite = new top.jsUnitTestSuite();             newsuite.addTestSuite(coreSuite());             newsuite.addTestSuite(serverSuite());             newsuite.addTestSuite(librariesSuite());             return newsuite;         }
  • 20. JSUnit  function testAssertNotUndefined() {       assertNotUndefined("1 should not be undefined", 1);       assertNotUndefined(1);   }      function testAssertNaN() {       assertNaN("a string should not be a number", "string");       assertNaN("string");   }      function testAssertNotNaN() {       assertNotNaN("1 should not be not a number", 1);       assertNotNaN(1);   }      function testFail() {       var excep = null;       try {           fail("Failure message");       } catch (e) {           excep = e;       }       assertJsUnitException("fail(string) should throw a JsUnitException", excep);   }      function testTooFewArguments() {       var excep = null;       try {           assert();       } catch (e1) {           excep = e1;       }       assertNonJsUnitException("Calling an assertion function with too  few arguments should throw an exception", excep);   }
  • 22. YUITest (2 & 3) ✦ Testing framework built and developed by Yahoo (released Oct 2008). ✦ Completely overhauled to go with YUI v3. ✦ Features: ✦ Supports async tests. ✦ Has good event simulation. ✦ v2: http://developer.yahoo.com/yui/ examples/yuitest/ ✦ v3: http://developer.yahoo.com/yui/3/test/
  • 23. YUITest 2   YAHOO.example.yuitest.ArrayTestCase = new YAHOO.tool.TestCase({       name : "Array Tests",              setUp : function () {           this.data = [0,1,2,3,4]       },              tearDown : function () {           delete this.data;       },                testPop : function () {           var Assert = YAHOO.util.Assert;                    var value = this.data.pop();                      Assert.areEqual(4, this.data.length);           Assert.areEqual(4, value);                   },                      testPush : function () {           var Assert = YAHOO.util.Assert;                      this.data.push(5);                      Assert.areEqual(6, this.data.length);           Assert.areEqual(5, this.data[5]);                   }  }); 
  • 25. YUITest 3  Y.example.test.DataTestCase = new Y.Test.Case({       name : "Data Tests",              setUp : function () {           this.data = {               name: "test",               year: 2007,               beta: true           };       },              tearDown : function () {           delete this.data;       },              testName : function () {           var Assert = Y.Assert;                      Assert.isObject(this.data);           Assert.isString(this.data.name);           Assert.areEqual("test", this.data.name);                   },              testYear : function () {           var Assert = Y.Assert;                      Assert.isObject(this.data);           Assert.isNumber(this.data.year);           Assert.areEqual(2007, this.data.year);                   }  }); 
  • 27. Behavior Testing ✦ Similar to unit testing, but broken up by task. ✦ Functionally very similar to unit testing, uses different terminology ✦ Popular frameworks: ✦ Screw.Unit ✦ JSSpec
  • 28. Screw.Unit ✦ Popular BDD framework. ✦ http://github.com/nathansobo/screw-unit/ tree/master
  • 29. Screw.Unit  describe("a nested describe", function() {     var invocations = [];        before(function() {       invocations.push("before");     });        describe("a doubly nested describe", function() {       before(function() {         invocations.push('inner before');       });          it("runs befores in all ancestors prior to an it", function() {         expect(invocations).to(equal, ["before", "inner before"]);       });     });   }); 
  • 31. JSSpec ✦ Used by MooTools as their testing framework. ✦ http://jania.pe.kr/aw/moin.cgi/JSSpec
  • 32. JSSpec  describe('"Should have"s', {     'String length': function() {       expect("Hello").should_have(4, "characters");     },     'Array length': function() {       expect([1,2,3]).should_have(4, "items");     },     'Object's item length': function() {       expect({name:'Alan Kang', email:'jania902@gmail.com', accounts:['A', 'B']}).should_have(3, "accounts");     },     'No match': function() {       expect("This is a string").should_have(5, "players");     },     'Exactly': function() {       expect([1,2,3]).should_have_exactly(2, "items");     },     'At least': function() {       expect([1,2,3]).should_have_at_least(4, "items");     },     'At most': function() {       expect([1,2,3]).should_have_at_most(2, "items");     }   }) 
  • 34. Automation ✦ Functional Testing ✦ Browser launching ✦ Server-Side
  • 35. Functional Testing ✦ Selenium IDE ✦ There may be others by Selenium is far and away the best.
  • 36. Selenium IDE ✦ Records and automates actions performed by a user. ✦ An extension for Firefox that records the actions. ✦ Can play them back in all browsers (limited by cross-domain issues). ✦ Primarily for testing web applications - everyone should use it, though! ✦ http://seleniumhq.org/projects/ide/
  • 38. Browser Launching ✦ Automates the process of opening browser windows, running tests, and getting results. ✦ Frequently require a specific framework. ✦ Popular frameworks: ✦ WebDriver http://code.google.com/p/ webdriver/ (Java) ✦ Waitr http://wtr.rubyforge.org/ (Ruby) ✦ JsTestDriver http://code.google.com/p/ js-test-driver/ (Java) ✦ Selenium RC http://seleniumhq.org/ projects/remote-control/ (Java)
  • 40. Server-Side ✦ Ignore the browser! Simulate it on the server-side. ✦ Almost always uses Java + Rhino to construct a browser. ✦ Some frameworks: ✦ Crosscheck ✦ Env.js ✦ Blueridge
  • 41. Server-Side ✦ Crosscheck ✦ Pure Java, even simulates browser bugs. ✦ http://www.thefrontside.net/crosscheck ✦ Env.js ✦ Pure JavaScript, focuses on standards support. ✦ http://github.com/thatcher/env-js/tree/ master ✦ Blueridge ✦ Env.js + Screw.Unit + Rhino ✦ http://github.com/relevance/blue-ridge/
  • 42. Env.js $ java -jar build/js.jar Rhino 1.6 release 6 2007 06 28 js> load('build/runtest/env.js'); js> window.location = 'test/index.html'; test/index.html js> load('dist/jquery.js'); // Add pretty printing to jQuery objects: js> jQuery.fn.toString = DOMNodeList.prototype.toString; js> $('span').remove(); [ <span#å°åŒ—Taibei>, <span#å°åŒ—>, <span#utf8class1>, <span#utf8class2>, <span#foo:bar>, <span#test.foo[5]bar> ] // Yes - UTF-8 is supported in DOM documents! js> $('span') [ ] js> $('div').append('<span><b>hello!</b> world</span>'); [ <div#main>, <div#foo> ] js> $('span') [ <span>, <span> ] js> $('span').text() hello! worldhello! world
  • 43. Distributed ✦ Selenium Grid ✦ Push Selenium tests out to many machines (that you manage), simultaneously. ✦ Collect and store the results. ✦ http://selenium-grid.seleniumhq.org/ ✦ TestSwarm ✦ Push tests to a distributed swarm of clients. ✦ Results viewable on the server. ✦ http://testswarm.com/
  • 46. Cost / Benefit IE 7 IE 6 FF 3 Safari 3 Opera 9.5 Cost Benefit Draw a line in the sand.
  • 47. Graded Support Yahoo Browser Compatibility
  • 48. Browser Support Grid IE Firefox Safari Opera Chrome Previous 6.0 2.0 3.0 9.5 Current 7.0 3.0 3.2 9.6 1.0 Next 8.0 3.1 4.0 10.0 2.0 jQuery Browser Support
  • 49. Browser Support Grid IE Firefox Safari Opera Chrome Previous 6.0 2.0 3.0 9.5 Current 7.0 3.0 3.2 9.6 1.0 Next 8.0 3.1 4.0 10.0 2.0 jQuery 1.3 Browser Support
  • 50. The Scaling Problem ✦ The Problem: ✦ jQuery has 6 test suites ✦ Run in 11 browsers ✦ (Not even including multiple platforms!) ✦ All need to be run for every commit, patch, and plugin. ✦ JavaScript testing doesn’t scale well.
  • 51. Distributed Testing ✦ Hub server ✦ Clients connect and help run tests ✦ A simple JavaScript client that can be run in all browsers ✦ Including mobile browsers! ✦ TestSwarm
  • 52. FF 3.5 FF 3.5 FF 3.5 IE 6 IE 6 FF 3 IE 6 Op 9 FF 3 IE 7 TestSwarm IE 7 Test Suite Test Suite Test Suite
  • 53. Manual Testing ✦ Push tests to users who follow pre-defined steps ✦ Answer ‘Yes’/’No’ questions which are pushed back to the server. ✦ An effective way to distribute manual test load to dozens of clients.
  • 54. TestSwarm.com ✦ Incentives for top testers (t-shirts, books) ✦ Will be opening for alpha testing very soon ✦ Help your favorite JavaScript library become better tested! ✦ http://testswarm.com
  • 55. Questions ✦ Contact: ✦ John Resig ✦ http://ejohn.org/ ✦ http://twitter.com/jeresig ✦ More info: ✦ http://jsninja.com/Overview ✦ http://ejohn.org/blog/javascript-testing- does-not-scale/