Time for action—testing the calculation of averages

Let's test the code you've just created.

  1. Double-click the JavaScript step.
  2. Click on the Test script button.
  3. A window appears to create a set of rows for testing. Fill it like here:
    Time for action—testing the calculation of averages
  4. Click on Preview the transformation. A window appears showing five identical rows with the provided sample values. Close the preview window.
  5. Click on OK to test the code.

    A window appears with the result that will appear when we execute the script with the test data.

    Time for action—testing the calculation of averages

What just happened?

You tested the code of the JavaScript step.

You clicked on the Test script button, and created a dataset that served as the basis for testing the script. You previewed the test dataset.

After that, you did the test itself. A window appeared showing you how the created dataset looks like after the execution of the script—the totalScore and wAverage fields were added, and the skill field was converted to uppercase.

Testing the script using the Test script button

The Test script button allows you to check that the script does what it is intended to do. It actually generates a transformation in the back with two steps—a Generate Rows step sending data to a copy of the JavaScript step. Just after clicking on the button, you are allowed to fill the Generates Rows window with the test dataset.

The first thing that the test function does is to verify that the code is properly written; that is, that there are no syntax errors in the code. Try deleting the last parenthesis in the code and click on the Test script button. When you click OK to see the result of the execution, instead of a dataset you will see an error window.

If the script is syntactically correct, what follows is the preview of the JavaScript for the transformation in the back, that is, the JavaScript code applied to the test dataset.

If you don't see any error and the previewed data shows the expected results, you are done. If not, you can check the code, fix it, and test it again until you see that the step works properly.

Have a go hero—testing the new calculation of the average

Open the transformation of the previous Hero section, and test:

  • The weighted average code
  • The regular code

    Tip

    To test one or the other, simply change the test data. Don't touch your code!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.229.161