Debugging tests step by step

In this recipe we will consider scripts debugging by doing a set of step-by-step instructions. This is necessary if we are left with some vague results after test execution, and a simple variable values lookup, at a given point of time, is insufficient.

Getting ready

To begin, we will require two functions, one of which is to be called from the other:

  1. Let's create the first function fn1:
    function fn1()
    {
      var n = 5, s = "str";
      Log.Message(n);
      Log.Message(s);
      return s;
    }
  2. Let's create the second function main so that it calls the first one twice, and then outputs the results into the log, as obtained due to the fn1 function call:
    function main()
    {
      var res1 = fn1();
      var res2 = fn1();
      Log.Message(res1);
      Log.Message(res2);
    }

How to do it...

In order to perform step-by-step execution in the debugging mode, it is necessary to complete the following actions:

  1. Set the breakpoint on the first line of the main function (to this end, set the cursor at this line, and press F9 button).
  2. Launch the main function. In the result, the function execution will pause.
  3. Press F10. As the result, the line where the cursor is set will be executed, and the fn1 function will come through; the res1 variable will have the str value assigned.
  4. Now the cursor is located on the following line with the second call of the fn1 function.
  5. Press F11. In the result, the cursor will relocate into the fn1 function, and we will have a possibility to execute the function step by step by pressing F10 key.
  6. Press F5. This will bring off the continuation of the function execution till the very end.

How it works...

In the debugging mode, we can perform the following commands:

  • Step Over (F10): This command executes the entire line of code and allows transition to the following code statement.
  • Step Into (F11): This command steps into the function that is being called in the current line (if possible). If one cannot step into the function, the Step Over command is to be executed.
  • Continue Execution (F5): This command continues the script execution from the current place down to the next breakpoint.
  • Run to Cursor (F4): This command goes on executing the function from the current line to the place where the text cursor has been set.
..................Content has been hidden....................

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