Skip to main content

Bot script testing

At the previous step, we have created a script for the bot that plays “Guess the Number” game with the 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 state = "/Rules"/>
<q>nah</q>
<a state = "/Rules/Agree/No"/>
</test-case>

<test-case id="2">
<q>/start</q>
<a state = "/Rules"/>
<q>sup?</q>
<a state = "/NoMatch"/>
</test-case>

<test-case id="3">
<random>1,2</random>
<q>/NoMatch</q>
<a>What do you mean?</a>
<q>/NoMatch</q>
<a>I don't get you</a>
<q>/NoMatch</q>
<a>I don't understand you</a>
</test-case>

<test-case id="4">
<q>/start</q>
<a>Let's play Guess Number game. I think of a number from 0 to 100, you guess. Ready to start?</a>
<q>yep</q>
<random>23</random>
<a>Make a guess</a>
<q>21</q>
<a>Bigger!</a>
<q>30</q>
<a>Hint: the number is smaller than yours</a>
<q>25</q>
<a>Smaller!</a>
<q>23</q>
<a>You won! Let's play one more time?</a>
<q>nope</q>
<a>That's a pity! If you change your mind, just text me "Lets's play"</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 client 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 if the bot moves to /Rules/Agree/No state when the user does not want to play.
  2. <test-case id="2"> — checks that the bot switches to /NoMatch state when the user sends a text that differs from options provided for in the script.
  3. <test-case id="3"> — checks if the random function works correctly in the /NoMatch state.
  4. <test-case id="4"> — checks the bot’s answers during the game.
tip
Learn more about bot script tests

Testing in a test widget

  1. The user doesn’t want to play the game.

Let’s make sure that the bot reacts correctly when the user doesn’t want to play the game.

Test widget

Now let’s check if the game starts again when the user sends Let’s play.

Test widget

  1. The user sends a text that differs from options provided for in the script.

Let’s assume that instead of agreeing to play the game, the user writes how are you?. In this case, the bot will respond with one randomly selected message from the NoMatch state. In addition, we will check that the bot hasn’t changed the context and hasn’t sent the message What’s your guess.

Test widget

  1. The user agrees to play the game.

Let’s try to guess the generated number. You can notice that the bot gives random answers according to selectRandomArg() function.

Test widget

Let’s try to send the message I don’t know and see that the bot sends the right answer and doesn’t switch the state.

Test widget

We have guessed the number and checked that the bot works correctly.

Test widget

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