Test Skills in Visual Studio Code


You can use the Alexa Skills Kit (ASK) Toolkit for Visual Studio Code (VS Code) to test your skill code locally against your skill invocations. You can test the code by routing requests to an Alexa proxy on your developer computer. Local testing enables you to verify changes to skill code without deploying skill code to Amazon Web Services (AWS) Lambda. You can test your skill without leaving VS Code by using the VS Code Alexa simulator page. You can also test your local skill by using other methods, such as the Alexa simulator in the Alexa developer console and the ASK Command Line Interface (CLI).

For prerequisites and installation instructions, see Get Started with the ASK Toolkit for VS Code.

Prerequisites

Before you can invoke your local skill, add ask-sdk-local-debug to your skill project. Follow the instructions for your SDK language to add ask-sdk-local-debug to your skill:

Set up the test environment

Before you test your skill in VS Code, you must add configuration to enable your skill to connect to the Alexa proxy.

To add Alexa debugger configuration

  1. Create a launch.json file for your skill, if you don't already have one.

    1. Open the Run menu, and then choose Add Configuration….
    2. In the Select Environment dialog box, choose your programming language, Node.js or Python.
      This action adds the launch.json file to your project and opens the file in the editor. You should see code similar to the following example.

      {
          "version": "0.2.0",
          "configurations": [
              {
                  "type": "node",
                  "request": "launch",
                  "name": "Launch Program",
                  "skipFiles": [
                      "<node_internals>/**"
                  ],
                  "program": "${file}"
              }
          ]
      }
      
  2. Add the Alexa debugger configurations to your launch.json file, if you haven't already.

    1. Open the Run menu, and then choose Add Configuration…
    2. From the list of options, choose ASK: Alexa Skills Debugger (Node.js) or ASK: Alexa Skills Debugger (Python).
      This action adds configuration code to the launch.json file. You should see code similar to the following example.

      {
          "version": "0.2.0",
          "configurations": [
              {
                  "name": "Debug Alexa Skill (Node.js)",
                  "type": "node",
                  "request": "launch",
                  "program": "${command:ask.debugAdapterPath}",
                  "args": [
                      "--accessToken",
                      "${command:ask.accessToken}",
                      "--skillId",
                      "${command:ask.skillIdFromWorkspace}",
                      "--handlerName",
                      "handler",
                      "--skillEntryFile",
                      "${workspaceFolder}/lambda/index.js"
                  ]
              },
              {
                  "type": "node",
                  "request": "launch",
                  "name": "Launch Program",
                  "skipFiles": [
                      "<node_internals>/**"
                  ],
                  "program": "${file}"
              }
          ]
      }
      
    3. Save the changes to the launch.json file.
  3. In the Alexa debugger configurations, specify the Alexa region where your developer account resides.
    The valid regions are Europe (EU), the Far East (FE), or North America (NA). The default region is North America.

    1. Find the Alexa region corresponding to the marketplace for your developer account by using the table at Hosting your skill resources in different AWS Regions.
    2. Open the launch.json file.
    3. Add or edit the region entry in the args array.
      Valid values for region are EU, FE, and NA. Your code should look like the following example.
      {
          "version": "0.2.0",
          "configurations": [
              {
                  "name": "Debug Alexa Skill (Node.js)",
                  "type": "node",
                  "request": "launch",
                  "program": "${command:ask.debugAdapterPath}",
                  "args": [
                      "--accessToken",
                      "${command:ask.accessToken}",
                      "--skillId",
                      "${command:ask.skillIdFromWorkspace}",
                      "--handlerName",
                      "handler",
                      "--skillEntryFile",
                      "${workspaceFolder}/lambda/index.js",
                      "--region",
                      "FE"
                  ]
              },
              {
                  "type": "node",
                  "request": "launch",
                  "name": "Launch Program",
                  "skipFiles": [
                      "<node_internals>/**"
                  ],
                  "program": "${file}"
              }
          ]
      }
      
    4. Save the changes to the launch.json file.

Test your local Alexa skill

Before you complete this procedure, complete the procedures in Prerequisites and Set up the test environment.

To test your local Alexa skill in VS Code

  1. Open the Run menu, and then choose Start Debugging.

    Your skill code starts and VS Code establishes a Web Socket connection from your computer to the Alexa proxy service. Requests to your skill are now routed directly to your local skill code as long as the connection with the Alexa proxy service is open. The connection remains open for one hour. You can't create more than one connection to a skill.

  2. Test your skill by using one of the following methods:

To stop testing your Alexa local skill

  • Open the Run menu, and then choose Stop Debugging.
    This action closes the connection to the Alexa proxy service. Alexa reverts to invoking the endpoint configured for your skill instead of your local skill.

Test your skill in the VS Code Alexa simulator

You can test your skill by using the Skill Simulation page in VS Code. By using the skill simulator, you can send utterances to Alexa and receive responses without leaving VS Code.

The following screenshot shows the Skill Simulation page in VS Code:

The skill simulation page in VS Code.

To test your local skill in the VS Code Alexa simulator

  1. In the activity bar, click the Alexa icon.
  2. On the ALEXA SKILLS TOOLKIT sidebar, click Skills, and then click to open your skill.
  3. Click Test skill, and then choose Open simulator.
  4. On the Skill Simulation page, in the Talk to Alexa section, for Skill stage, choose Development.
    This action enables your skill for testing, and activates the utterance text box at the end of the page.
  5. For Locale, choose the language and locale that you want to test.
    Your skill must contain an interaction model for the language and locale that you select. For details, see Interaction Model.
  6. In the text box at the end of the page enter an utterance, and then click Send.
    The simulator sends your request to Alexa, and the response appears.
  7. After you receive the response, you can perform the following actions:

    • To view the JSON for the most recent request and response, select the Skill I/O tab.
    • To view information, such as considered intents, select the Execution Info tab.
    • To see how the response from your skill appears on a device screen, select the Device Preview tab.
      • To choose from round, small, medium, large, or full-screen TV views, use Change viewport.
      • To select an item in the display, click the item you want.
  8. Repeat the previous step, as needed.
    You can enter new utterances, or use the up and down arrows on your keyboard to enter previous utterances quickly. You can't enter a new utterance until Alexa has responded to the previous request. If you registered a virtual device, Alexa plays audio responses.
  9. At any time, to clear the utterances and responses in the Talk to Alexa section, click the Reset button.
  10. To disable your skill for testing and end your testing session, enter exit in the text box, and then click Send.

Save and replay sessions in the VS Code Alexa simulator

When you test your skill, you might want to send the same utterances to Alexa repeatedly. You can save the utterances that you enter during a test session, and then replay them later.

To save and replay a test session in the VS Code Alexa simulator

  1. To save a session, click the Export button.
    The simulator saves your utterances as a json file, and then asks you for a location to save the file.
  2. To replay a session, on the ALEXA SKILLS TOOLKIT sidebar, click Skills, and then click to open your skill.
  3. Click Test skill, and then choose Replay session.
    The simulator asks you for the location of a file that you saved previously. After you specify the file, the utterances replay in the simulator.
  4. To disable your skill for testing and end your testing session, enter exit in the text box, and then click Send.

Was this page helpful?

Last updated: Jun 21, 2024