Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Bespoken unit-test scripts with new readme.md #26

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# No Webstorm files
/.idea

# Logs
logs
*.log
Expand Down Expand Up @@ -57,5 +60,7 @@ typings/
# dotenv environment variables file
.env

# IDEs
.idea

.DS_Store
18 changes: 18 additions & 0 deletions lambda/custom/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions test/unit/index.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#=====================================================================================================================
# ______ _ ____ ______ __ _
# / __/ /__ (_) / / /_ __/__ ___ / /_(_)__ ___ _
# _\ \/ '_// / / / / / / -_|_-</ __/ / _ \/ _ `/
# /___/_/\_\/_/_/_/ /_/ \__/___/\__/_/_//_/\_, /
# /___/
#
# Created by Bespoken
# Learn more at https://read.bespoken.io/unit-testing/getting-started/
#
# Skill name: "Pet Match" by Amazon
# Test scope: LaunchRequest, PetMatchIntent, AMAZON.HelpIntent, AMAZON.StopIntent, AMAZON.CancelIntent
# Description: General test suite for all intents
#=====================================================================================================================

---
configuration:
locale: en-US

---
- test: Launch request, no further interaction
- LaunchRequest:
- prompt: Welcome to pet match
- reprompt: What size and temperament are you looking for in a dog
- sessionEnded: false

---
- test: Simple utterance, no slot value provided
- PetMatchIntent:
- prompt:
- There are dogs that are tiny, small, medium, and large
- What size of a dog would you like?
- AMAZON.StopIntent: Bye

---
- test: The size and pet slot values are provided on open
- PetMatchIntent size=small pet=dog:
- prompt:
- Would you prefer a dog to hang out with kids or to protect you?
- Are you looking for more of a family dog or a guard dog?
- AMAZON.StopIntent: Bye

---
- test: Complete dialog sequence, starting with energy
- PetMatchIntent pet=dog energy=high:
- prompt:
- There are dogs that are tiny, small, medium, and large
- What size of a dog would you like?
- PetMatchIntent size=small: Are you looking for more of a family dog or a guard dog?
- PetMatchIntent temperament=guard: So a small \n guard \n high \n energy dog sounds good for you. Consider a \n toy fox terrier
- SessionEndedRequest:
- response.outputSpeech: undefined

---
- test: Disambiguation of slots
- LaunchRequest
- PetMatchIntent size=mini: What size are you looking for
- PetMatchIntent size=small: Are you looking for more of a family dog or a guard dog?
- PetMatchIntent temperament=guard: Do you prefer high energy or low energy dogs?
- PetMatchIntent energy=low: So a small \n guard \n low \n energy dog sounds good for you. Consider a \n miniature snouser

---
- test: No matching slots
- LaunchRequest
- PetMatchIntent size=dummy: What size are you looking for
53 changes: 53 additions & 0 deletions test/unit/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## **How to setup and run Unit Tests**

There are several methods commonly used to test and simulate Alexa skills during the development process.
See the Alexa Cookbook [testing guide](https://github.com/alexa/alexa-cookbook/tree/master/guides/testing) for more details.

For running formal QA tests, developers can leverage third-party tools that run on standard unit test frameworks like [Jest](https://jestjs.io/) or [Mocha](https://mochajs.org/).

Here we will focus on running a test suite against your local code project using the Bespoken CLI (`bst`) from [Bespoken](https://bespoken.io).

To get started, you need to install the Bespoken CLI, please follow the next steps:
1. Install the Bespoken CLI by running `npm install -g bespoken-tools` on your command line.
2. Create the main testing folder. We recommend to name it `test`; it should be under the root of your skill's directory.
3. Create a folder named `unit` under `test\`, this folder will store your unit test script files.
4. Add the test configuration file `testing.json`. This file should be located under your `test\unit` directory. It might look like this:
```JSON
{
"handler": "../../src/index.js",
"locale": "en-US",
"trace": true,
"jest": {
"silent": false
}
}
```
The most important parameter is the handler where you indicate Bespoken's Skill Tester where the source code of your skill is. These parameters can be overwritten on each test script file under their configuration section.
5. Add your test scripts. We recommend to use next convention when naming your test script files:
* If you have only one test script: `index.test.yml`
* If you want to create more than one test script: `functionalityName.test.yml`.

The yml extension indicates this is a YAML file, which is the syntax we use to create test scripts; `test` means that is a unit test script file. A test script looks like this:
```YAML
---
configuration: # Here you define your locales and mocks
locale: en-US

--- # Three dashes start a new YAML document
- test: Launch request, no further interaction. # A description of this test sequence
- LaunchRequest: # LaunchRequest is not an utterance but a request type
- response.outputSpeech.ssml: Here's your fact
- response.card.type: Simple
- response.card.title: Space Facts
- response.card.content: "*" # A wildcard means any text will match
```
A typical YAML sentence is composed of 2 parts separated by a colon; in the left part we have the intent name we want to test; in the right part we have the expected result. You can also access any element on the JSON response object like the session attributes.
6. To execute the scripts go to the root of your project and run `bst test`. That will find and run all the unit test scripts files.

For more information about skill unit testing with Bespoken, please read [here](https://read.bespoken.io/unit-testing/getting-started/).

If you need assistance, reach Bespoken on any of these channels:
* [Chat with us](https://bespoken.io/testing) (chat is in lower right-hand corner of the page)
* [Email](mailto:[email protected])
* [Twitter](https://twitter.com/bespokenio)
* [Gitter](https://gitter.im/bespoken)
10 changes: 10 additions & 0 deletions test/unit/testing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"handler": "../../lambda/custom/index.js",
"trace": false,
"jest": {
"silent": true,
"coveragePathIgnorePatterns": [
"<rootDir>/analytics"
]
}
}