Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Lately Amazon has been working on improving the developer experience for its Alexa intelligent personal assistant. Part of this strategy Skill Management API,provides the ability to test multi-turn conversation, entity resolution, dialog management, and more features that are not supported by existing test tools.
Testing Alexa Skill with Postman supersedes the basic testing service provided by the Amazon Developer Portal.
To start, we are going to use three things to make all of this work
We need threee things to get started
If you havenât built a skill for Alexa before, I would suggest , go through Build skill in 5 minutes and get started with core principles .
Once you gotten your Lambda function set up and running we are good to go .
Function might be looking something like this
With Amazon API Gateway, we can provide Alexa with a consistent and scalable programming interface to access endpoints in the backend.
- To begin with , go to AWS API Gateway and sign in to the console.
- First, make sure that you have chosen âNew APIâ from the radio buttons at the top of the page.Then make a new role and choose âLambda execution roleâ
- Now you need to open the Actions button, and this time choose âDeploy API.â In the Deploy API box that appears, choose â[New Stage]â for Deployment/Test stage. For the other three values (Stage Name, Stage description, and Deployment description), you can just use the word âTestâ for all of them. The values donât matter, itâs just so that you know what the purpose of this new API is for.We gonna need this at later stage.
4.Now Now , Copy the Invoke URL from the blue box at the top of the screen. Your API is set up and ready to roll.
- Getting up and running with Postman APIÂ Tool
- If you donât already have this Amazing tool, make sure to download Postman. but wait âŠ
Why Postman ?
- In this article , We will be using Postman to create and execute our unit tests against our Lambda function.Each time that you make a change to your Lambda, you should run your tests to make sure that everything is still working as expected
- We have something Amazing called Monitors , Which will help us to save overhead in Unittesting Alexa Skills .
- Postman helps us writing pre-request scripts and test scripts for requests , based on TDD. and hell yeah , Postman collections are Making API testing great again.
- I work at Postman. đ
Alright , So now you are up and running Postman hopefully.
If you need more security for each requests over API gateway then you can add AWS Signatures and Proceed.
Now you need a sample request get started with testing. You can get a Lambda request from the Service Simulator like serverless , or from your Cloudwatch logs in amazon account.
Choose body and click on ârawâ radio button , which indicates we are forwarding our own JSON data to Lambda.
Output will be embdded "SSML": Indicates that the output speech is text marked up with SSML. Itâs a way by which alexa communicates.
You can know more about Request structure here.
At this point be sure and verified that you can successfully communicate with your Lambda, Now we can start creating a suite of tests for this request which will define units .
For Example , We are using favorite color skill, âWhatsMyColorIntent what my favorite colorâ should return âorange"
pm.test("Body is correct", function () { pm.response.to.have.body("orange");});
Similary when you want to check if Alexa continues the skill after user gives a response and reprompts for input , We need to check field shouldEndSession
Similarly you can define set of tests for a Alexa Skill and run it everytime you make some changes in skill. Postman will help you to know breaks when you make any unexpected change in the request or code.
This way you save much of time and spend writing code instead of boring testing.
You can also save Alexa response to Postman and write test without calling Prod API again again for one session.You can learn more here. You can run your collection in Runner and Know status of your Skill.
Monitor Skills on Postmanâs cloud.
Now ,If you are CLI freak like me , you would prefer testing all of Tests from Command Line right ?
No problem , Postman has a tool called , newman , itâs a command line companion for Postman.
Install newman by npm install newman --global with NodeJS.
Thatâs it. Now itâs time to get hands dirty with Collections in CLI.
Now , Run your tests in CLI with
newman run AlexaSkillTesting/test_to_check_color.json
And Thatâs it. See your terminal talking to Postman and Testing for you .
And Yes , Postman Monitors can surely help by keeping an eyes on response and notifies when something goes wrong. Because , Weâre going to write an entire suite of unit tests for our skill so that when we make a change to something, we have the confidence that nothing has broken and Everything is 200 OK . And It Absolutely helps us in functional testing of Skill at each conversational phase. So , Cheers đș
Hopefully , I have helped you in testing alexa skills . Thanks for reading đ
Supercharged Unit Testing of Alexa skills with Postman and Newman was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.