TS 73 JavaScriptUnitTests

Revision as of 07:40, 16 September 2013 by Vriha (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

JavaScript Unit Tests support Test Specification for NetBeans 7.3

Author: Vladimir Riha
Last update: 3rd October 2012
Introduction: Test specification for JavaScript Unit Tests in NetBeans

Mac OS specific details: To find Options on MacOS, go to Netbeans menu -> Preferences

For some reasons, Jasmine tests do not work with JS Test Driver 1.3.5. Please use older version instead (or propose some fix ;))

Contents


Prerequisites & Trivia

  • Download js-test-driver from http://code.google.com/p/js-test-driver/downloads/list
  • js-test-driver need (by default) jsTestDriver.conf. NetBeans expect this file to be in you configuration files
  • this conf file can contain: list of files to be loaded, list of files to be excluded and other settings
  • the sample application contains some test files and libraries in "tests" folder (extracted from AngularJS template). Tests as such are in "unit" folder (for Jasmine) and "qunit" (for QUnit)

Jasmine tests

  • The sample application contains basic Jasmine tests. The configuration file is called
jsTestDriver_jasmine.conf
  • To use it, remove the "_jasmine" part from its name and Test project


QUnit tests

  • The sample application contains basic QUnit tests. The configuration file is called
jsTestDriver_qunit.conf
  • To use it, remove the "_qunit" part from its name and Test project
  • IMPORTANT: test functions in TestCase have to start with "test"

Test Suites

Test suite: Configuration and Test execution

  1. Install js-test-driver
    1. Right click on your HTML/JavaScript project and select Test
    2. File:Ts73_jsunitconf.png
    3. Similar dialog to the one above is opened, specify path to the jar file downloaded from the link in Prerequisites
    4. Modify port number and which browser to be run (note that more than 2 browsers might cause troubles)
    5. Confirm the dialog
    6. File:Ts73_jsunitrun.png
    • EXPECTED RESULT: New page/tab is opened in selected browsers with so called slave page. These are required and can contain useful information such as logging or information about failures. When all tests are finished, you can see results in NetBeans and results are separated by browser (image below). Check output window and see 2 tabs: js-test-driver Server and Running JS unit tests. In Services window, there is a new node called "JS Test Driver".
  2. Test configuration file
    1. In the sample project, expand Configuration Files node and open jsTestDriver.conf
    • EXPECTED RESULT: Content of the file is colored, try to copy the content to some YAML file. Coloring should be identical
  3. Missing configuration file
    1. By default, the NetBeans uses jsTestDriver.conf located in your Configuration Files
    2. Rename this file
    3. Run tests
    • EXPECTED RESULT: Test action item is disabled and you cannot run test.
  4. Change driver configuration
    1. Open Services window and right click on JS Test Driver
    2. Select Configure
    • EXPECTED RESULT: Dialog similar to the one on top of this page is opened. Change some settings and run tests again to be sure that these changes are respected.
  5. Stop JS Test Driver
    1. Open Services window and right click on JS Test Driver
    2. Select Stop
    • EXPECTED RESULT: The driver is stopped, icon is missing the green triangle and header of the "js-test-driver Server" output window is not bold. Slave page in browser is now gray. Try to start it again.

Test suite: Running tests using external JSTestDriver

  1. External JSTestDriver
    1. NetBeans supports to run tests on external JSTestDriver "server". To test it, start JSTestDriver from command line (single line)
me@pc:sampleApp/config$ java -jar JsTestDriver.jar 
--runnerMode DEBUG --config jsTestDriver_external.conf --port 9876
    1. Now open http://localhost:9876 and click on Capture this browser
    2. Go to Services window and right click on "JS Test Driver"
    3. Select Configure
    4. Enter the URL above and specify path to jstestdriver jar and select the captured browser
    5. Confirm the dialog
    6. Test project
    • EXPECTED RESULT: Tests were executed as expected. If you go to Services window again, you can see that you cannot start/stop this external JS Test Driver from its context menu.

Test suite: Debugging tests

  1. Debugging Unit Tests
    1. Open sampleApp/tests/unit/jasmine.js and add breakpoint to line 12 (with var calc)
    2. Select project node in Projects and click on Test
    3. Specify common parameters and as a browser add "Chrome with NetBeans JS Debugger"
    4. Confirm the dialog
    5. Test project
    • EXPECTED RESULT: Tests are executed and code execution stops at the line breakpoint. From now on all common debugging features should be working. You can follow these instructions. Note that DOM breakpoints may not work.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo