SlideShare a Scribd company logo
Efficient JavaScript Unit Testing
Hazem Saleh

09 March 2013
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
Developers Life without Unit testing

Complex integration between the system components.
Developers Life without Unit testing

Unmanaged number of new/regression defects especially when
the system complexity increases.
Developers Life without Unit testing
Low application quality.

Longer testing cycle.


                                  fix   test
                           test                fix


                     fix                             test



                  test                                  fix



                     fix                             test


                           test                fix
                                  fix   test
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
What is unit testing and why?

A unit testing is a piece of code (usually a method) that
invokes another piece of code and later checks the correctness of
some assumptions


Unit testing helps in detecting BUGGY components in the early
stages of the project.


A test suite is a set of test cases, and a test case is a set of tests
which verifies the system components.
Good Unit Test Characteristics

                     Automated



   Repeatable                             Fast



   Easy to run.                        Incremental



                  Easy to understand
What is unit testing and why?

Integration is much simplified.

Defects are managed. Regression defects should not happen if the defect is
resolved by creating a new test case.

Test cases can be a good reference for system documentation.

Test cases can improve the system design and be the basis of code refactoring.

Application quality increases.

Testing cycle is reduced.
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
Current Complexities in testing JavaScript code

                                    Slow

   Requires a lot of time to test on all the browsers.

   JavaScript code that runs on a specific browser does not necessarily
   mean that it will work on other browsers.

                                 Inflexible

    Supporting a new browser means allocating a new budget for
    testing the system again on this new browser and for the
    new/regression defects fixes.
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
Good JavaScript Unit Testing Tool Requirements

                             JavaScript unit
                               testing tool

Can execute across all                               Fast Test case
the browsers over                                    execution.
 all the platforms.



               Easy setup.                 Integration with IDEs.



 Easy configuration.                             Integration with build
                                                 management tools.
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
What is JsTestDriver

  One of the best Open source JavaScript testing tools.

  Meets all of the previous requirements and more:

             Supports all the browsers / all platforms. ✓

             Easy setup and configuration. ✓

             Fast Test case execution. ✓

             Integration with IDEs and build management tools. ✓
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
                                Configuration.
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
JsTestDriver Architecture
JsTestDriver configuration


1   Run the test cases using the following command line
JsTestDriver configuration


1   2   Download the jsTestDriver latest jars from


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

            Create the jsTestDriver.conf file (under the JS folder)
1   2   3   with the following initial content:



        server: http://localhost:9876
        load:
         - js-src/*.js
         - js-test/*.js
JsTestDriver configuration

                      Start the server using the following command
1       2   3   4     line




    java -jar JsTestDriver-1.3.2.jar
   Optional parameters
     [--port 9876]
     [--browser
      “{PATH}firefox.exe","{PATH}iexplore.exe","{P
      ATH}Safari.exe"]
JsTestDriver configuration

                               Run the test cases using the following
  1    2     3     4     5     command line



java -jar JsTestDriver-1.3.2.jar --tests all
.........
Total 9 tests (Passed: 9; Fails: 0; Errors: 0) (16.00 ms)
  Firefox 9.0.1 Windows: Run 3 tests (Passed: 3; Fails: 0; Errors 0)
(3.00 ms)
  Safari 534.52.7 Windows: Run 3 tests (Passed: 3; Fails: 0; Errors
0) (4.00 ms)
  Microsoft Internet Explorer 7.0 Windows: Run 3 tests (Passed: 3;
Fails: 0; Errors 0) (16.00 ms)
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
    JsTestDriver Eclipse plugin.
I
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
JsTestDriver Eclipse plugin


Instead of using command lines for starting the server and running the test
cases, you can directly use the jsTestDriver Eclipse plugin.



To install the JsTestDriver Eclipse plugin install the plugin from the following
URL : http://js-test-driver.googlecode.com/svn/update/
JsTestDriver Eclipse plugin
JsTestDriver Eclipse plugin
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
Writing a JavaScript TestCase

ApplicationUtilTest = TestCase("ApplicationUtilTest");

ApplicationUtilTest.prototype.setUp = function () {
   /*:DOC += ...HTML fragment code goes here (single root) ...*/
};

ApplicationUtilTest.prototype.testMethod1 = function () {
  … validate using the jsTestDriver constructs …
}

ApplicationUtilTest.prototype.testMethod2 = function () {
  … validate using the jsTestDriver constructs …
}

...
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
JsTestDriver common constructs

    fail("msg")

    assertTrue("msg", actual)

    assertFalse("msg", actual)

    assertSame("msg", expected, actual)

    assertNotSame("msg", expected, actual)

    assertNull("msg", actual)

    assertNotNull("msg", actual)
DEMO
Let’s write synchronous JS
       Test cases …
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility
    Generating reports from test cases.
Writing asynchronous JavaScript TestCase
AsyncTest = AsyncTestCase("AsynchronousTesting");

AsyncTest.prototype.setUp = function () {
/*:DOC += <!-- Initialization code -->*/
};
AsyncTest.prototype.testOperationOne = function(queue) {
    queue.call('Step1', function(callbacks) {
    var asyncObject = new AsyncObject ();

       var successCallBack = callbacks.add(function(successData) {
            // validate (successData) if possible ....
        });

        var failureCallBack = callbacks.addErrback('Error Message');

       // call asynchronous API
       asyncObject.operationOne(inputData,
                                  successCallBack,
                                failureCallBack);
 });
};
Writing asynchronous JavaScript TestCase
Every inline function provides a callbacks parameter for
testing the Ajax APIs. There are two types of
callbacks:
• Success callback: Represents the success path. It
  MUST be called in order to pass the test.
• Error callback: Represents the error path. If it is
  called, then the test fails.


The test runner does not move to the next queue until
the current queue executes all of its success callbacks. If
a specific success callback is not called for a specific
amount of time (30 seconds), the test fails.
DEMO
Let’s write Asynchronous JS
       Test cases …
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility

    Generating reports from test cases.
JsTestDriver Compatibility


JsTestDriver is not only a JavaScript unit testing
framework BUT it is a test runner for many other
JavaScript unit testing frameworks.

JsTestDriver is compatibility with the following
JavaScript unit testing frameworks through adapters:
   • Jasmine
   • YUI Test
   • QUnit
JsTestDriver Compatibility


In order to run the previous unit testing frameworks
on the top of the JSTD test runner. You need to
configure the framework adapter and source before
the test files as follows:

 server: http://localhost:9876

 load:
  - jasmine/lib/jasmine-1.1.0/jasmine.js
  - jasmine/lib/adapter/JasmineAdapter.js
  - js-src/Basics.js
  - js-test/BasicsSpec.js
DEMO
Running Jasmine Test cases
   on the top of JSTD
Developers Life without Unit testing.

    What is unit testing? and why?

    Current Complexities in testing JavaScript code.

    Requirements of a good JavaScript unit testing tool.
O
U   What is JsTestDriver.
T   JsTestDriver Architecture & Configuration
L
I   JsTestDriver Eclipse plugin.
N   Writing a JavaScript TestCase.
E   JsTestDriver common constructs.

    Writing asynchronous JavaScript TestCase.

    JsTestDriver Compatibility

    Generating reports from test cases.
Generating reports from test cases


JSTD can generate code coverage files.

Code coverage describes how much the source code is tested.


Coverage Criteria:

                     Function coverage

                                 statement coverage

                                            Branch
                                                 coverage
JsTestDriver
   can generate code coverage
for your JavaScript code using the
      code coverage plugin.
Generating reports from test cases



           Configuring the plugin:
Download the      Add the coverage plugin declaration   Specify the --
“coverage.jar”.   to the configuration file:            testOutput
                  plugin:                               <<output_folder>>
                                                        flag in the test
                  - name: "coverage"                    running command.
                  jar: "plugins/coverage.jar"
                  module:
                  "com.google.jstestdriver.coverage.C
                  overageModule"
Generating reports from test cases


Unfortunately   JsTestDriver does not generate HTML reports directly,

                       JsTestDriver generates the test coverage files in LCOV
                       and XML formats.

                You can generate the HTML test reports using the
                LCOV visualizer tool:

                       http://ltp.sourceforge.net/coverage/lcov.php
Generating reports from test cases


       The JsTestDriver LCOV file name is usually:

              <config filename>-coverage.dat (jsTestDriver.conf-
              coverage.dat)

       To generate the report from the LCOV file using the
       LCOV visualizer tool:

              genhtml jsTestDriver.conf-coverage.dat
Conclusion
Conclusion

  Testing JavaScript code is important for increasing the
  application quality and for speeding up fixing defects and
  minimizing the number of regression defects.


  Good JavaScript tool should be configurable, easy to use,
  and working with all the browsers.


  JsTestDriver is one of the most powerful JavaScript unit
  testing tools that can be used for testing both synchronous
  and asynchronous JavaScript code on all the browsers.
Question of the session (Free book copy)

<script>
(function() {
  var x = 10,
   y = 20,
   z = x+++y;
  alert(x);   //?
  alert(y);   //?
  alert(z);   //?
})();
</script>           http://www.amazon.com/dp/1782160620/
                    JavaScript Unit Testing Book
Contact me

Twitter: http://www.twitter.com/hazems
LinkedIn: http://eg.linkedin.com/in/hazemsaleh
Blog: http://www.technicaladvices.com
Email: hazems@apache.org

More Related Content

What's hot

Testing In Java
Testing In JavaTesting In Java
Testing In Java
David Noble
 
Test ng
Test ngTest ng
Test ng
fbenault
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
Stefano Paluello
 
JUnit 5
JUnit 5JUnit 5
JMockit
JMockitJMockit
JMockit
Angad Rajput
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
Rody Middelkoop
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
kgayda
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Thomas Zimmermann
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Scott Leberknight
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
Testacular
TestacularTestacular
Testacular
James Ford
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactus
Himanshu
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
Mike Lively
 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questions
Kuldeep Pawar
 
[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android
Hazem Saleh
 
Mockito vs JMockit, battle of the mocking frameworks
Mockito vs JMockit, battle of the mocking frameworksMockito vs JMockit, battle of the mocking frameworks
Mockito vs JMockit, battle of the mocking frameworks
EndranNL
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialJAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
Anup Singh
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
Stephen Fuqua
 
Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
Dave Bouwman
 

What's hot (20)

Testing In Java
Testing In JavaTesting In Java
Testing In Java
 
Test ng
Test ngTest ng
Test ng
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
JMockit
JMockitJMockit
JMockit
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
Testacular
TestacularTestacular
Testacular
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactus
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questions
 
[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android
 
Mockito vs JMockit, battle of the mocking frameworks
Mockito vs JMockit, battle of the mocking frameworksMockito vs JMockit, battle of the mocking frameworks
Mockito vs JMockit, battle of the mocking frameworks
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialJAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
 

Viewers also liked

Visage Android - Cleaner APIs, Cleaner UIs
Visage Android - Cleaner APIs, Cleaner UIsVisage Android - Cleaner APIs, Cleaner UIs
Visage Android - Cleaner APIs, Cleaner UIs
Stephen Chin
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
Stephen Chin
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011
Stephen Chin
 
Orishas mitos-y-leyendas
Orishas mitos-y-leyendasOrishas mitos-y-leyendas
Orishas mitos-y-leyendas
mibarra758
 
Beginning Android Flash Development - GTUG Edition
Beginning Android Flash Development - GTUG EditionBeginning Android Flash Development - GTUG Edition
Beginning Android Flash Development - GTUG Edition
Stephen Chin
 
DukeScript
DukeScriptDukeScript
DukeScript
Stephen Chin
 
JCrete Embedded Java Workshop
JCrete Embedded Java WorkshopJCrete Embedded Java Workshop
JCrete Embedded Java Workshop
Stephen Chin
 

Viewers also liked (7)

Visage Android - Cleaner APIs, Cleaner UIs
Visage Android - Cleaner APIs, Cleaner UIsVisage Android - Cleaner APIs, Cleaner UIs
Visage Android - Cleaner APIs, Cleaner UIs
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011
 
Orishas mitos-y-leyendas
Orishas mitos-y-leyendasOrishas mitos-y-leyendas
Orishas mitos-y-leyendas
 
Beginning Android Flash Development - GTUG Edition
Beginning Android Flash Development - GTUG EditionBeginning Android Flash Development - GTUG Edition
Beginning Android Flash Development - GTUG Edition
 
DukeScript
DukeScriptDukeScript
DukeScript
 
JCrete Embedded Java Workshop
JCrete Embedded Java WorkshopJCrete Embedded Java Workshop
JCrete Embedded Java Workshop
 

Similar to Efficient JavaScript Unit Testing, March 2013

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
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
Christian Johansen
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
romanovfedor
 
[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript
Hazem Saleh
 
JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101
Hazem Saleh
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
UTC Fire & Security
 
Javascript Unit Testing
Javascript Unit TestingJavascript Unit Testing
Javascript Unit Testing
Tom Van Herreweghe
 
Angular Unit testing.pptx
Angular Unit testing.pptxAngular Unit testing.pptx
Angular Unit testing.pptx
RiyaBangera
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
Lilia Sfaxi
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web developmentalice yang
 
Unit test
Unit testUnit test
Unit test
Tran Duc
 
Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...
Rachid Kherrazi
 
Qa process
Qa processQa process
Qa process
Aila Bogasieru
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
Mats Bryntse
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS app
Aleks Zinevych
 

Similar to Efficient JavaScript Unit Testing, March 2013 (20)

Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
 
[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript
 
JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Javascript Unit Testing
Javascript Unit TestingJavascript Unit Testing
Javascript Unit Testing
 
Angular Unit testing.pptx
Angular Unit testing.pptxAngular Unit testing.pptx
Angular Unit testing.pptx
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web development
 
Unit test
Unit testUnit test
Unit test
 
Lesson 2
Lesson 2Lesson 2
Lesson 2
 
Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...
 
Qa process
Qa processQa process
Qa process
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS app
 

More from Hazem Saleh

Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018
Hazem Saleh
 
[ApacheCon 2016] Advanced Apache Cordova
[ApacheCon 2016] Advanced Apache Cordova[ApacheCon 2016] Advanced Apache Cordova
[ApacheCon 2016] Advanced Apache Cordova
Hazem Saleh
 
[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action
Hazem Saleh
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In Action
Hazem Saleh
 
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
Hazem Saleh
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
Hazem Saleh
 
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
Hazem Saleh
 
Dojo >= 1.7 Kickstart
Dojo >= 1.7  KickstartDojo >= 1.7  Kickstart
Dojo >= 1.7 Kickstart
Hazem Saleh
 
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
Hazem Saleh
 
JSF Mashups in Action
JSF Mashups in ActionJSF Mashups in Action
JSF Mashups in Action
Hazem Saleh
 
JavaScript tools
JavaScript toolsJavaScript tools
JavaScript tools
Hazem Saleh
 
[JavaOne 2010] Abstract Mashups for Enterprise Java
[JavaOne 2010] Abstract Mashups for Enterprise Java[JavaOne 2010] Abstract Mashups for Enterprise Java
[JavaOne 2010] Abstract Mashups for Enterprise Java
Hazem Saleh
 
GMaps4JSF
GMaps4JSFGMaps4JSF
GMaps4JSF
Hazem Saleh
 

More from Hazem Saleh (13)

Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018
 
[ApacheCon 2016] Advanced Apache Cordova
[ApacheCon 2016] Advanced Apache Cordova[ApacheCon 2016] Advanced Apache Cordova
[ApacheCon 2016] Advanced Apache Cordova
 
[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action
 
Apache Cordova In Action
Apache Cordova In ActionApache Cordova In Action
Apache Cordova In Action
 
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
 
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
 
Dojo >= 1.7 Kickstart
Dojo >= 1.7  KickstartDojo >= 1.7  Kickstart
Dojo >= 1.7 Kickstart
 
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
 
JSF Mashups in Action
JSF Mashups in ActionJSF Mashups in Action
JSF Mashups in Action
 
JavaScript tools
JavaScript toolsJavaScript tools
JavaScript tools
 
[JavaOne 2010] Abstract Mashups for Enterprise Java
[JavaOne 2010] Abstract Mashups for Enterprise Java[JavaOne 2010] Abstract Mashups for Enterprise Java
[JavaOne 2010] Abstract Mashups for Enterprise Java
 
GMaps4JSF
GMaps4JSFGMaps4JSF
GMaps4JSF
 

Recently uploaded

Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 

Efficient JavaScript Unit Testing, March 2013

  • 1. Efficient JavaScript Unit Testing Hazem Saleh 09 March 2013
  • 2. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 3. Developers Life without Unit testing Complex integration between the system components.
  • 4. Developers Life without Unit testing Unmanaged number of new/regression defects especially when the system complexity increases.
  • 5. Developers Life without Unit testing Low application quality. Longer testing cycle. fix test test fix fix test test fix fix test test fix fix test
  • 6. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 7. What is unit testing and why? A unit testing is a piece of code (usually a method) that invokes another piece of code and later checks the correctness of some assumptions Unit testing helps in detecting BUGGY components in the early stages of the project. A test suite is a set of test cases, and a test case is a set of tests which verifies the system components.
  • 8. Good Unit Test Characteristics Automated Repeatable Fast Easy to run. Incremental Easy to understand
  • 9. What is unit testing and why? Integration is much simplified. Defects are managed. Regression defects should not happen if the defect is resolved by creating a new test case. Test cases can be a good reference for system documentation. Test cases can improve the system design and be the basis of code refactoring. Application quality increases. Testing cycle is reduced.
  • 10. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 11. Current Complexities in testing JavaScript code Slow Requires a lot of time to test on all the browsers. JavaScript code that runs on a specific browser does not necessarily mean that it will work on other browsers. Inflexible Supporting a new browser means allocating a new budget for testing the system again on this new browser and for the new/regression defects fixes.
  • 12. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 13. Good JavaScript Unit Testing Tool Requirements JavaScript unit testing tool Can execute across all Fast Test case the browsers over execution. all the platforms. Easy setup. Integration with IDEs. Easy configuration. Integration with build management tools.
  • 14. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 15. What is JsTestDriver One of the best Open source JavaScript testing tools. Meets all of the previous requirements and more: Supports all the browsers / all platforms. ✓ Easy setup and configuration. ✓ Fast Test case execution. ✓ Integration with IDEs and build management tools. ✓
  • 16. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration Configuration. L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 18. JsTestDriver configuration 1 Run the test cases using the following command line
  • 19. JsTestDriver configuration 1 2 Download the jsTestDriver latest jars from http://code.google.com/p/js-test-driver/downloads/list
  • 20. JsTestDriver configuration Create the jsTestDriver.conf file (under the JS folder) 1 2 3 with the following initial content: server: http://localhost:9876 load: - js-src/*.js - js-test/*.js
  • 21. JsTestDriver configuration Start the server using the following command 1 2 3 4 line java -jar JsTestDriver-1.3.2.jar  Optional parameters  [--port 9876]  [--browser “{PATH}firefox.exe","{PATH}iexplore.exe","{P ATH}Safari.exe"]
  • 22. JsTestDriver configuration Run the test cases using the following 1 2 3 4 5 command line java -jar JsTestDriver-1.3.2.jar --tests all ......... Total 9 tests (Passed: 9; Fails: 0; Errors: 0) (16.00 ms) Firefox 9.0.1 Windows: Run 3 tests (Passed: 3; Fails: 0; Errors 0) (3.00 ms) Safari 534.52.7 Windows: Run 3 tests (Passed: 3; Fails: 0; Errors 0) (4.00 ms) Microsoft Internet Explorer 7.0 Windows: Run 3 tests (Passed: 3; Fails: 0; Errors 0) (16.00 ms)
  • 23. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L JsTestDriver Eclipse plugin. I N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 24. JsTestDriver Eclipse plugin Instead of using command lines for starting the server and running the test cases, you can directly use the jsTestDriver Eclipse plugin. To install the JsTestDriver Eclipse plugin install the plugin from the following URL : http://js-test-driver.googlecode.com/svn/update/
  • 27. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 28. Writing a JavaScript TestCase ApplicationUtilTest = TestCase("ApplicationUtilTest"); ApplicationUtilTest.prototype.setUp = function () { /*:DOC += ...HTML fragment code goes here (single root) ...*/ }; ApplicationUtilTest.prototype.testMethod1 = function () { … validate using the jsTestDriver constructs … } ApplicationUtilTest.prototype.testMethod2 = function () { … validate using the jsTestDriver constructs … } ...
  • 29. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 30. JsTestDriver common constructs fail("msg") assertTrue("msg", actual) assertFalse("msg", actual) assertSame("msg", expected, actual) assertNotSame("msg", expected, actual) assertNull("msg", actual) assertNotNull("msg", actual)
  • 31. DEMO Let’s write synchronous JS Test cases …
  • 32. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 33. Writing asynchronous JavaScript TestCase AsyncTest = AsyncTestCase("AsynchronousTesting"); AsyncTest.prototype.setUp = function () { /*:DOC += <!-- Initialization code -->*/ }; AsyncTest.prototype.testOperationOne = function(queue) { queue.call('Step1', function(callbacks) { var asyncObject = new AsyncObject (); var successCallBack = callbacks.add(function(successData) { // validate (successData) if possible .... }); var failureCallBack = callbacks.addErrback('Error Message'); // call asynchronous API asyncObject.operationOne(inputData, successCallBack, failureCallBack); }); };
  • 34. Writing asynchronous JavaScript TestCase Every inline function provides a callbacks parameter for testing the Ajax APIs. There are two types of callbacks: • Success callback: Represents the success path. It MUST be called in order to pass the test. • Error callback: Represents the error path. If it is called, then the test fails. The test runner does not move to the next queue until the current queue executes all of its success callbacks. If a specific success callback is not called for a specific amount of time (30 seconds), the test fails.
  • 35. DEMO Let’s write Asynchronous JS Test cases …
  • 36. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 37. JsTestDriver Compatibility JsTestDriver is not only a JavaScript unit testing framework BUT it is a test runner for many other JavaScript unit testing frameworks. JsTestDriver is compatibility with the following JavaScript unit testing frameworks through adapters: • Jasmine • YUI Test • QUnit
  • 38. JsTestDriver Compatibility In order to run the previous unit testing frameworks on the top of the JSTD test runner. You need to configure the framework adapter and source before the test files as follows: server: http://localhost:9876 load: - jasmine/lib/jasmine-1.1.0/jasmine.js - jasmine/lib/adapter/JasmineAdapter.js - js-src/Basics.js - js-test/BasicsSpec.js
  • 39. DEMO Running Jasmine Test cases on the top of JSTD
  • 40. Developers Life without Unit testing. What is unit testing? and why? Current Complexities in testing JavaScript code. Requirements of a good JavaScript unit testing tool. O U What is JsTestDriver. T JsTestDriver Architecture & Configuration L I JsTestDriver Eclipse plugin. N Writing a JavaScript TestCase. E JsTestDriver common constructs. Writing asynchronous JavaScript TestCase. JsTestDriver Compatibility Generating reports from test cases.
  • 41. Generating reports from test cases JSTD can generate code coverage files. Code coverage describes how much the source code is tested. Coverage Criteria: Function coverage statement coverage Branch coverage
  • 42. JsTestDriver can generate code coverage for your JavaScript code using the code coverage plugin.
  • 43. Generating reports from test cases Configuring the plugin: Download the Add the coverage plugin declaration Specify the -- “coverage.jar”. to the configuration file: testOutput plugin: <<output_folder>> flag in the test - name: "coverage" running command. jar: "plugins/coverage.jar" module: "com.google.jstestdriver.coverage.C overageModule"
  • 44. Generating reports from test cases Unfortunately JsTestDriver does not generate HTML reports directly, JsTestDriver generates the test coverage files in LCOV and XML formats. You can generate the HTML test reports using the LCOV visualizer tool: http://ltp.sourceforge.net/coverage/lcov.php
  • 45. Generating reports from test cases The JsTestDriver LCOV file name is usually: <config filename>-coverage.dat (jsTestDriver.conf- coverage.dat) To generate the report from the LCOV file using the LCOV visualizer tool: genhtml jsTestDriver.conf-coverage.dat
  • 47. Conclusion Testing JavaScript code is important for increasing the application quality and for speeding up fixing defects and minimizing the number of regression defects. Good JavaScript tool should be configurable, easy to use, and working with all the browsers. JsTestDriver is one of the most powerful JavaScript unit testing tools that can be used for testing both synchronous and asynchronous JavaScript code on all the browsers.
  • 48. Question of the session (Free book copy) <script> (function() { var x = 10, y = 20, z = x+++y; alert(x); //? alert(y); //? alert(z); //? })(); </script> http://www.amazon.com/dp/1782160620/ JavaScript Unit Testing Book
  • 49.
  • 50. Contact me Twitter: http://www.twitter.com/hazems LinkedIn: http://eg.linkedin.com/in/hazemsaleh Blog: http://www.technicaladvices.com Email: hazems@apache.org