bbc/alexa-skill-test-framework

Name: alexa-skill-test-framework

Owner: BBC

Description: Framework for easy offline black-box testing of Alexa skills.

Forked from: BrianMacIntosh/alexa-skill-test-framework

Created: 2017-07-25 10:28:47.0

Updated: 2017-09-22 12:43:13.0

Pushed: 2017-09-14 15:24:25.0

Homepage: null

Size: 71

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Alexa Skill Test Framework

This framework makes it easy to create full-coverage black box tests for an Alexa skill using Mocha.

Here's an example of what a test might look like with the test framework.

ribe("AMAZON.HelpIntent into AMAZON.CancelIntent", function(){
exaTest.test([
{ request: alexaTest.getIntentRequest("AMAZON.HelpIntent"), says: alexaTest.t("HELP_MESSAGE"), shouldEndSession: false },
{ request: alexaTest.getIntentRequest("AMAZON.CancelIntent"), says: alexaTest.t("STOP_MESSAGE"), shouldEndSession: true }
;

How To

Install the package as a dev dependency with npm install alexa-skill-test-framework --save-dev.

Write tests in a Javascript file and run them with Mocha. For example, if your test is at 'test/index.js', run mocha test/index.js.

For some simple examples, see the 'examples' directory.

Test Framework Documentation
alexaTest.initialize(index, appId, userId, deviceId)

Initializes the test framework. Must be called before generating requests or running any tests.

alexaTest.initializeI18N(resources)

Initializes i18n. You only need this if you use i18n in your skill, and you want to use i18n to fetch result strings to test against. You must have installed the optional dependencies i18n and i18next-sprintf-postprocessor.

alexaTest.setLocale(locale)

Changes the locale used by the test framework and the skill. Default is 'en-US'.

alexaTest.setDynamoDBTable(tableName)

Activates mocking of DynamoDB backed attributes.

alexaTest.unmockDynamoDB()

Removes the mock on the AWS SDK.

alexaTest.setExtraFeature(key, state)

Enables or disabled an optional test feature.

Current features are:

alexaTest.getLaunchRequest([locale])

Returns a LaunchRequest. The request can be passed to test (see below).

alexaTest.getIntentRequest(intentName, [slots], [locale])

Returns an IntentRequest. The request can be passed to test (see below).

alexaTest.getSessionEndedRequest(reason, [locale])

Returns a SessionEndedRequest. The request can be passed to test (see below).

addAudioPlayerContextToRequest(request, [token], [offset], [activity])

Adds an AudioPlayer context to the given request. Returns the given request to allow call chaining.

alexaTest.addEntityResolutionToRequest(request, slotName, slotType, value, [id])

Adds an entity resolution to the given request. Returns the given request to allow call chaining.

alexaTest.addEntityResolutionNoMatchToRequest(request, slotName, slotType, value)

Adds an entity resolution with code ER_SUCCESS_NO_MATCH to the given request. Returns the given request to allow call chaining.

alexaTest.test(sequence, [description])

Tests the skill with a sequence of requests and expected responses. This method should be called from inside a Mocha describe block.

The playsStream Object has the following properties:

alexaTest.t(arguments)

Forwards the request to alexaTest.i18n.t and returns the result. You must have called alexaTest.initializeI18N previously.

CallbackContext Documentation

Callback context objects are passed to callback and saysCallback in tests.

context.assert(data)

Throws an assertion error.

context.t(arguments)

Forwards the request to alexaTest.i18n.t and returns the result. Additionally, ensures the language is the language used in the request. You must have called alexaTest.initializeI18N previously.

Note About DynamoDB

If your skill uses the Alexa Skills Kit for Node.js and uses its built-in DynamoDB persistence, it may be desireable not to connect to the database during testing, since the ASK Node kit uses it to persist session attributes. For that case, the framework passes a fourth parameter of true to the handler function, which you can conditionalize on to disable the database connection.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.