Photo by Andres Urena on Unsplash
According to Wikipedia, it means “Requirements are turned into very specific test cases, then the software is improved to pass the new tests, only.” Basically, you would first have to write the test of the software/feature you are developing before you start working on the developing the software/feature itself.
Here are a few more articles on the benefits and why you should apply TDD:- Test Driven Development by Jan Olbrich- Isn’t TDD twice the work? Why should you care? by Navdeep Singh
Here are a few thing you might want to have set up or installed before getting started:
mkdir project-name
)cd project-name
)npm init
)test command:
, put in node test/testflow.js
instead. The command line should look something like the snippet below.
This utility will walk you through creating a package.json file.It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fieldsand exactly what they do.
Use `npm install <pkg>` afterwards to install a package andsave it as a dependency in the package.json file.
Press ^C at any time to quit.package name: (emptyproject)version: (1.0.0)description:entry point: (index.js)test command: node test/testflow.jsgit repository:keywords:author:license: (ISC)
Now you have node.js setup for the project.
Shout out to robmccauley for maintaining testflow that provides unit testing for Alexa skills. Here’s what the following commands will do :
git submodule add
instead of git clone
.)
git clone [email protected]:robm26/testflow.git testmkdir dialogstouch dialogs/default.txtsed -i '9c const SourceCodeFile = "../index.js"' test/testflow.js
Inside the ‘default.txt’ file in the ‘dialogs’ folder, you should have the intents you are trying to test. The default in the testflow repository consist of the followings but you should definitely add some more customized ones to it depending on what you are trying to do in your skill.
LaunchRequestAMAZON.HelpIntentAMAZON.StopIntent
In case where you are taking in variables through utterances, you can do something like this :
DoSomething Input1=userInput1 Input2=userInput2
To get a deeper understanding into using testflow, I recommend looking into its tutorial page and the blog post by the author himself.
To be honest, I don’t have too much to talk about on this topic. Here is some sample code of how a sample skill can look like. (Also remember to do npm install --save alexa-sdk
.)
I recommend looking into the official Alexa GitHub repository that provides all kinds of sample skills that you can work on top of.
Go to this page and select ‘Create Skill’. In there you should see options to ‘add intents’ and ‘custom slot types’. You should add the appropriate slot types and intents accordingly from above. After you are done with that, select ‘Endpoint’ from the side bar and select ‘AWS Lambda ARN’ as the skill’s service endpoint. Make a copy of the Skill ID as you will need it later.
Create an AWS Lambda function selecting ‘from scratch’. After that, you should have an option to ‘add trigger’ where you would select ‘Alexa Skills Kit’. Now in the configuration dialog, you should put in the Skill ID you took a copy of previously then select ‘Add’.
After this, select back to the box that labeled your project name. There should be a ‘Function code’ dialog box appeared below. While you can definitely copy and paste your code onto the online text editor, there might be chance where the packages you have installed and used in your code is included by default. It is also possible that you have more than 1 JavaScript files for the skill.
In this case, you would select ‘Upload a .ZIP file’ under ‘Code entry type’. Locally, zip up all the JavaScript files along with the node_modules
folder then upload the resulting zip file.
When you are done, you can go back to the Alexa Skill Kit page, select the ‘Distribution’ tab and fill out the appropriate information before submitting your skill for review. Hopefully everything goes well and your skill gets published at the Alexa Skill Store!
I recently started working at Facebook as a Software Engineer. I spend a lot of my free time experimenting and building new things with technologies I find fun and interesting. Follow my exploration journey here or on GitHub.