Skip to main content

Bot script testing

At the previous step, we have created a script for the bot that plays “Last Letter Game” with a user.

Now, let’s test the bot before deploying it to make sure we haven’t made mistakes in the script. After that, we can test the game in the test widget to check the transitions between the states.

.xml tests

Let’s write a simple test to check the transitions between states. Create test.xml in test folder and paste the following:

<test>
<test-case id="1">
<q>/start</q>
<a>Hey! Let's play "Cities" Game. Who will start first: bot or user?</a>
<q>me</q>
<a>Name the city</a>
<q>Krakow</q>
<a state="/LetsPlayCitiesGame/CityPattern"></a>
</test-case>

<test-case id="2">
<q>/start</q>
<a>Hey! Let's play "Cities" Game. Who will start first: bot or user?</a>
<q>me</q>
<a>Name the city</a>
<q>HK</q>
<a>Please use only full cities name</a>
</test-case>

<test-case id="3">
<q>/start</q>
<a>Hey! Let's play "Cities" Game. Who will start first: bot or user?</a>
<q>not me</q>
<a state="/start/Computer"></a>
<a state="/LetsPlayCitiesGame"></a>
</test-case>

<test-case id="4">
<state>LetsPlayCitiesGame</state>
<q>stop</q>
<a>That's a pity! If you change your mind, just text me "Lets's play"</a>
<q>let's play</q>
<a>Hey! Let's play "Cities" Game. Who will start first: bot or user?</a>
</test-case>
</test>

Click the Save the script icon on the right side of the upper panel to save your script.

Each test-case checks if the actual response of the bot to a specific question corresponds to user intentions. A user reply is usually identified with the <q> tag, a reaction is identified as <a>.

We can assign id to each test-case:

  1. <test-case id="1"> — checks the start of the game and a user’s decision to start the game first.
  2. <test-case id="2"> — checks if a user can enter a short city name.
  3. <test-case id="3"> — checks if the bot moves to the /LetsPlayCitiesGame state when a user writes not me.
  4. <test-case id="4"> — checks the transitions between states, if a user wants to finish the game and then starts it again.
tip
Learn more about bot script tests

Testing in a test widget

  1. The user starts the game:

Test widget

  1. The bot starts the game:

Test widget

  1. Let’s name a city that has been named before and then name a non-existent city.

Test widget

  1. Let’s use a short city name:

Test widget

  1. Let’s try to finish the game and then start it again:

Test widget

Now you can connect the channel yourself and play with the bot.