Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing Alexa skill that uses alexa-sdk

I'm developing an Alexa skill in node and I'd like to know how I can unit test my code. I'm using the alexa sdk that Amazon released.

I've found many libraries to accomplish this, but they seem to be developed before the alexa sdk was available.

Thanks in advance.

like image 244
froinds Avatar asked Feb 12 '17 17:02

froinds


1 Answers

We built our Alexa emulator specifically for the purpose of allowing easy unit-testing and functional-testing of Alexa skills:
http://docs.bespoken.tools/en/latest/tutorials/tutorial_bst_emulator_nodejs/

With it, you can make calls like this:

alexa.launched(function (error, response) {
    alexa.spoken('About the podcast', function (error, response) {
        assert.equal(response.response.outputSpeech.ssml, '<speak> Some SSML </speak>');
        done();
    });
});

This test code imitates a user launching the skill and saying "About the Podcast". These interactions are automatically translated to the correct Alexa JSON requests, which in turn are then sent to your skill code.

You can also create more sophisticated unit-tests that rely on mimicking the internal state of Alexa device across interactions. These are described in the tutorial.

like image 84
John Kelvie Avatar answered Oct 16 '22 11:10

John Kelvie