JavaScript tutorial:
Testing and debugging your code

 

Unless you are writing very simple scripts, your code will need to be tested, and any errors found will have to be fixed.

Structural walk-through

The idea behind a structural walk-through is that four eyes can see more than two. This type of testing involves you presenting the code to another person or to an entire inspection team. It is structured so that you:

Describe the unit (module) being implemented

Explain how the unit connects to the other units, and

Specify the inputs and the outputs.

Having established the scene, you guide your helper(s) step-by-step through the program logic.

Black-box testing

This commonly used type of testing involves supplying the inputs and observing the outputs without going into the internal functioning of the unit being tested.

For example, if you are testing a function, you call it and supply the parameters (if any), and observe the output.

For JavaScript, normally you would need to:

Create a web page to use your function

Provide a driver mechanism to call your function, and

Display the result (e.g. in an alert box).

Luckily, with your JavaScript Editor you do not have to do all this, the black-box testing is greatly simplified:

You run JavaScript code directly, by highlighting the part you wish to execute, and clicking the Execute button. This functionality is unique to JavaScript Editor and no other editor supports it.

If you are testing JavaScript operating on a web page, click on Show Internal Viewer. You can then arbitrarily call any JavaScript function available to the page, specify the parameters, and observe the output. This is also something you can find only in JavaScript Editor. The program remembers your calls in case you need to repeat the test with changed parameters.

For an in-depth instructions on Syntax Check, running JavaScript and debugging your code using JavaScript Editor, please refer to the Editor reference, section Running and Testing JavaScript Code.

Next