On this website we use cookies that are strictly necessary to make our website function correctly, as well as optional – analytics, performance and/or marketing - cookies which help us improve our website by collecting and reporting information on how the website is used, as well as help us to reach out to you with information about our organization or offer. If you do not wish to accept optional cookies when visiting our website, you may change the settings in the Cookie Settings. For more information go to Cookie Settings.

Skip to content

How to make bot unit testing easy

Technology

Feb 13, 2018 - 2 minutes read

KBS_8133
Jakub Kaczmarek
See all Jakub's posts

Share

Bot development using Microsoft Bot Framework is easy and enjoyable. It doesn't take a lot of time to setup basic bot you can talk to. However, things are getting more complicated if you want to develop high-quality, unit-tested bot code for your customer. Since code quality is very important value for my organization, I was asked to develop a testing framework for bots, which would make dialog unit testing easy and intuitive.

Bot dialog story

My task was easier thanks to an existing library developed by my company colleague - Sławomir Kopacz. It's called Bot.Test.Stories and it's available on GitHub and NuGet. It allows to record a conversation between the user and bot dialog in a very intuitive way.

Objectivity.Bot.Tests.Stories.Xunit library

The unit testing framework I've created allows to take an advantage of Stories concept to write unit tests for your dialogs. It's available on NuGet and it's source code is available on GitHub. With this library unit testing is very simple - you just need to setup a class deriving a generic DialogUnitTestBase class, write a test story and play it:

The framework enhances the Stories concept with some additional ending variants to allow the developer verify the way the tested dialog was finished:

  • DialogDone() - verifies the dialog was done (context.Done() was called):

  • DialogDoneWithResult(predicate) - verifies the dialog was done and checks the result predicate:

  • DialogFailed() - verifies the dialog failed (context.Fail() was called):

  • DialogFailedWithExceptionOfType() - verifies the dialog failed with the exception type equal to provided in generic attribute:

More examples can be found on GitHub in samples project.

The post was initially published on JakubCodes.pl blog.

Jakub Kaczmarek
See all Jakub's posts

Related posts

You might be also interested in

Contact

Start your project with Objectivity

CTA Pattern - Contact - Middle