Custom tests

The quickest way to understand how tests work is to create a new scenario using one of our built-in templates: Dog Facts or Crypto Cap. We will go with the Crypto Cap in this example.

After you finish creating the scenario, you can open the Tests tab and see bunch of test code we’ve written for you. The code is well documented, but we’ll go though it here anyway.

The test file begins with the following heading:

---
tests:

After that you can put a name of your first test followed by a colon:

---
tests:

  Test of one random coin:

After the name of the test you can start writing the actual test steps.

Each step is a combination of what the User might say (the intent the user invokes) and what we are waiting for the Alexa / Google Home to answer:

---
tests:

  Test of one random coin:

  - say: start
    wait: What coin are you interested in?

In the example above the user would invoke a built-in intent start by saying something like Open Crypto Cap.

We then wait for Alexa / Google Home to ask a User for the coin a question:

What coin are you interested in?

Where does this question come from? Let’s take a look at our Scenario tab:

    - name: Initial Step
      entrypoint: true
      actions:
        - sendText: 'What coin are you interested in?'
        - getInput:
      next:
        which_coin: API Request
        help: Help
        AMAZON.CancelIntent: Exit
        AMAZON.StopIntent: Exit
        AMAZON.HelpIntent: Help

So essentially we’re testing the execution of the Initial Step.

Do you want to see your first test in action? Head over to the Test tab and you will see the name of your test Test of one random coin and the Run button next to it.

Press the Run button and don’t forget to turn on the sound to hear your test as well:

Now that we see that our greeting works, let’s move further and actually test when the user is saying the name of the coin she wants to know the price of:

---
tests:

  Test of one random coin:

    - say: start
      wait: What coin are you interested in?

    - say: which_coin
      slots:
        coin_name: bitcoin
      wait: >
        The price of {{coin_name}} is currently \d+\.\d{1,2} dollars.
        Do you want to know a price for another coin?

We do that by writing the next step of the test. In this step the user might activate which_coin intent by saying something like ‘How much is {coin_name}’.

How do we know that? Take a look at the Intents tab:

---
intents:
  which_coin:
    - 'How much is {coin_name}'
    - 'What is the price of {coin_name}'
    - 'How much {coin_name} costs'
    - 'How much does {coin_name} costs'
    - 'I am interested in {coin_name}'
    - '{coin_name}'
    - 'Current price of {coin_name}'
    - 'What is the current price of {coin_name}'

Ok, but how do we know which slot the user will put into the {coin_name} variable? We emulate it by introducing the slots section of the test step. Take a look at this code section once again:

- say: which_coin
  slots:
    coin_name: bitcoin

Here we essentially tell the BotTalk tester to use bitcoin as the value of the coin_name slot.

And what are we waiting for Alexa / Google Home to answer? Since we’re working with the live API that fetches the price of the crypto currencies in the real time - we use regular expressions to match the answer:

wait: >
  The price of {{coin_name}} is currently \d+\.\d{1,2} dollars.
  Do you want to know a price for another coin?

Let’s see our whole test in action!

It’s starting to look great. We now can test if our scenario works in retrieving the price of Bitcoin. But let us move even further. Let’s test if ANY cryptocurrency price could be retrieved as well.

In order to do that we would somehow need to replace the value we entered manually - bitcoin - with something dynamic.

BotTalk can do that for you, if you just leave the slot section out completely:

- say: which_coin
  wait: The price of {{coin_name}} is currently \d+\.\d{1,2} dollars.
  Do you want to know a price for another coin?

In this case BotTalk will randomly take any value you have provided in your Slots tab and fill it in.

The complete Test case will look something like that:

Notice how we’ve got one error, because our test was expecting two digits after a decimal point? That is by design. And we’ll leave this as a small exercise for you.


Written by Andrey Esaulov on 12 March 2019

Updated on 12 March 2019