Diff for "JavaScriptIntegrationTesting"

Not logged in - Log In / Register

Differences between revisions 5 and 17 (spanning 12 versions)
Revision 5 as of 2009-09-25 19:00:44
Size: 1731
Editor: abentley
Comment: speling
Revision 17 as of 2011-12-21 20:34:00
Size: 2511
Editor: bac
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from TestingJavaScript
Line 3: Line 4:
= Testing JavaScript = = YUIXHR Integration Testing in JavaScript =
Line 5: Line 6:
Launchpad's JavaScript testing consists of unit tests built with [[http://developer.yahoo.com/yui/3/|YUI 3's]] [[http://developer.yahoo.com/yui/3/yuitest/|yuitest]] library, and automated acceptance testing using the [[Windmill]] framework. We use the GradedBrowserSupport chart to determine which browsers code should be regularly tested in. Launchpad's JavaScript testing is built arount [[http://developer.yahoo.com/yui/3/|YUI 3's]]
[[http://developer.yahoo.com/yui/3/yuitest/|yuitest]] library.
We use the GradedBrowserSupport chart to determine which browsers code should be regularly tested in.
Line 7: Line 10:
== Testing Launchpad == Every JavaScript component should be tested first and foremost using [[JavascriptUnitTesting|unit testing]].
Line 9: Line 12:
Critical functions in Launchpad that have been enhanced by JavaScript, like editing a bug title, are tested using Windmill. Check the [[Windmill]] page for instructions on running the test suite. We have infrastructure to write tests centered on the integration between the JavaScript component and the app
server (regular API or view/++model++ page api.)
Line 11: Line 15:
== Testing the lazr-js Widget Library == These are still written using the `yuitest` library, but they are loaded and can access a "real" appserver
(the one started by the AppServerLayer).
Line 13: Line 18:
Launchpad makes use of the lazr-js widget library, as well as YUI. The Launchpad Windmill tests exercise critical functionality, leaving the comprehensive testing to the lazr-js library itself. The testing framwork also allows testing integration of the component on the
page itself (answering the question: Is it hooked up properly?) through
loading a page through an iframe for inspection. XXX: Give more information on how to do this.
Line 15: Line 22:
=== Running the lazr-js unit tests === == Creating the tests ==
Line 17: Line 24:
The unit tests can be run stand-alone from the [[https://edge.launchpad.net/lazr-js|lazr-js]] project.   * Use `standard_yuixhr_test_template.js` `standard_yuixhr_test_template.py` in the root of the Launchpad tree
  as templates. Copy and rename both files to the same directory. (You can put them in the usual `javascript/tests`
  subdirectory.)
  * The `.js` file contains the tests using the standard `yuitest` library.
  * The `.py` file contains fixtures that will operate within the app server. They should create content
  (through the standard LaunchpadObjectFactory) that will
  be accessed by the test (through. The database is automatically reset after every test.
Line 19: Line 32:
To run the lazr-js test suite: == Running the tests ==
Line 21: Line 34:
 1. Grab a copy of the lazr-js trunk: {{{ bzr get lp:lazr-js }}}
 1. Change to the `tests/` directory of the component you want to test. For example, `$ cd src/inlineeditor/tests/`.
 1. Load any HTML files you find into your browser. The test suite will run automatically.
  * We have tests discoverer that will make these tests run automatically as part of the test suite.
  * To run manually, start the test-appserver using:
    {{{
        make run-testapp
    }}}
  * Visit in your browser `https://launchpad.dev:8085/+yuitest/`''path-to-test-basename-from-root''. So for example,
  if you copied the templates to `lib/lp/bugs/javascript/tests/test_some_xhr.js`, you can run the tests by accessing
  `https://launchapd.dev:8085/+yuitest/lib/lp/bugs/javascript/tests/test_some_xhr`.
Line 25: Line 43:
  ''This process is really onerous - maybe the YUI 2 Test``Manager offers a better way to handle this. -- [[LaunchpadHome:mars]] <<DateTime(2009-02-26T15:43:40Z)>>'' == Gotchas ==
Line 27: Line 45:
=== Acceptance testing lazr-js widgets ===

You can try out stand-alone versions of the lazr-js widgets using the `examples/` pages. E.g.:

{{{
$ firefox examples/inlineedit/index.html
}}}

 * When loading `https://launchpad.dev:8085/+yuitest` if you see "cannot import Python fixture file" it may be due to not having {{{__init__.py}}} files in the directory and parent directories where you've put your new `.py` test fixture.

YUIXHR Integration Testing in JavaScript

Launchpad's JavaScript testing is built arount YUI 3's yuitest library. We use the GradedBrowserSupport chart to determine which browsers code should be regularly tested in.

Every JavaScript component should be tested first and foremost using unit testing.

We have infrastructure to write tests centered on the integration between the JavaScript component and the app server (regular API or view/++model++ page api.)

These are still written using the yuitest library, but they are loaded and can access a "real" appserver (the one started by the AppServerLayer).

The testing framwork also allows testing integration of the component on the page itself (answering the question: Is it hooked up properly?) through loading a page through an iframe for inspection. XXX: Give more information on how to do this.

Creating the tests

  • Use standard_yuixhr_test_template.js standard_yuixhr_test_template.py in the root of the Launchpad tree as templates. Copy and rename both files to the same directory. (You can put them in the usual javascript/tests subdirectory.)

  • The .js file contains the tests using the standard yuitest library.

  • The .py file contains fixtures that will operate within the app server. They should create content (through the standard LaunchpadObjectFactory) that will be accessed by the test (through. The database is automatically reset after every test.

Running the tests

  • We have tests discoverer that will make these tests run automatically as part of the test suite.
  • To run manually, start the test-appserver using:
    •         make run-testapp
  • Visit in your browser https://launchpad.dev:8085/+yuitest/path-to-test-basename-from-root. So for example, if you copied the templates to lib/lp/bugs/javascript/tests/test_some_xhr.js, you can run the tests by accessing https://launchapd.dev:8085/+yuitest/lib/lp/bugs/javascript/tests/test_some_xhr.

Gotchas

  • When loading https://launchpad.dev:8085/+yuitest if you see "cannot import Python fixture file" it may be due to not having __init__.py files in the directory and parent directories where you've put your new .py test fixture.


CategoryJavaScript CategoryTesting

JavaScriptIntegrationTesting (last edited 2011-12-21 20:34:00 by bac)