We can do this using Scenario Outlines. Think of these as a template that we setup and can then feed data into to run multiple tests.
Let's revisit the example from the previous page.
Feature: current-weatherScenario: current local weatherGiven an English speaking userWhen the user says "tell me the weather"Then "my-weather-skill" should reply with "Right now, it's overcast clouds and 32 degrees."
In this Scenario, when the user says "tell me weather", then our Weather Skill should reply with an appropriate dialog. However we know that there are many ways to ask about the weather. Rather than copy and pasting this Scenario for each utterance, we can instead use a
Feature: current-weatherScenario Outline: current local weatherGiven an english speaking userWhen the user says "<current local weather>"Then "mycroft-weather" should reply with "Right now, it's overcast clouds and 32 degrees."Examples: local weather questions # Table heading| current local weather | # Column heading| tell me the weather | # First value| what's the weather like | # Second value| current weather | # Third value
The most obvious change is the new block of
Examples. This is a table of data that we want to use in our Scenario. We give that table a title "local weather questions", and for each column in the table we provide a column heading "current local weather", followed by one or more values.
To use this data, we must first explicitly change from using a
Scenario to using a
Scenario Outline. We are then able to use the
Examples data in our Steps by including the Column Heading surrounding by angle brackets. In this case we have added
<current local weather> to the
When Step on line 4.
Running the above Scenario Outline will test three versions of this Scenario - "tell me the weather", "what's the weather like", and "current weather". It is important to note that "current local weather" is a heading, not a value, and it will not be tested.
So far we have only used the Scenario Outline to take in a list of utterances. The same format can be used with tables of data.
Feature: Pokemon abilitiesScenario Outline: list abilitiesGiven an english speaking userWhen the user says "What abilities does <Name> have"Then "pokemon.retrodaredevil" should reply with "<Name> has <Abilities>"Examples: Pokemon data # Table heading| Name | Abilities | # Column heading| Bulbasaur | chlorophyll and overgrow | # First value| Charmander | solar-power and blaze | # Second value| Squirtle | rain-dish and torrent | # Third value
In our new
Examples block, you can see we have expanded this into a two-column table containing the names of some Pokemon and the abilities they have. Using this data we have done two things.
With the Pokemon
Name, we have used this in both the question and the response.
The Abilities that are reported back are directly related to the Name from the same table row. If a user was to say "What abilities does Bulbasaur have", and Mycroft replied with "Bulbasaur has solar-power and blaze", then the Scenario would be considered a fail.