Mercurial > js4py-pl
view core-javascript/testtools.rst @ 201:b6864a86e876 default tip
Przetłumaczone getting-started
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 15 Jul 2012 13:27:27 +0200 |
| parents | 71b7fd796ddf |
| children | b04f509bee83 |
line wrap: on
line source
Test tools ========== To make it easier to test code, and to ensure that example code is correct, there is a small testtools.js file in the work folder. How to write tests ------------------ To prepare a test create a file like this. It's also in the work folder. (For real examples the file will give *assert* a more interesting argument, whose truth or falsity is perhaps not obvious.) .. literalinclude:: /core-javascript-work/demo_testtools.js :language: javascript How to run tests ---------------- Here's how to run the tests at the command line, finishing with a command prompt that allows you inspect the state and also run the test again. Rhino ^^^^^ For Rhino use *load* to run the test again. .. code-block:: sh core-javascript-work$ js -f testtools.js -f demo_testtools.js -f - Testing: all-pass Testing: 2-4-fail ! assert 2 has failed ! assert 4 has failed Rhino 1.7 release 2 2010 01 20 js> load('demo_testtools.js') // You type this. Testing: all-pass Testing: 2-4-fail ! assert 2 has failed ! assert 4 has failed js> JSDB ^^^^ For JSDB use *run* to run the test again. .. code-block:: sh C:core-javascript-work> jsdb -load testtools.js -load demo_testtools.js Testing: all-pass Testing: 2-4-fail ! assert 2 has failed ! assert 4 has failed js> load('demo_testtools.js') // You type this. Testing: all-pass Testing: 2-4-fail ! assert 2 has failed ! assert 4 has failed js> testools.js ----------- (Optional on a first reading.) Here's the file testools.js. It's short and simple (and has a not-nice dependency on global variables). It also has a branch based on whether it's being run on JSDB or Rhino. .. literalinclude:: /core-javascript-work/testtools.js :language: javascript
