Skip to content

How to make bot unit testing easy

Technology

Feb 13, 2018 - 2 minute read

KBS_8133
Jakub Kaczmarek
See all Jakub's posts

2988 HC Digital Transformation 476X381

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.

2988 HC Digital Transformation 476X381
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

We use necessary cookies for the functionality of our website, as well as optional cookies for analytic, performance and/or marketing purposes. Collecting and reporting information via optional cookies helps us improve our website and reach out to you with information regarding our organisaton or offer. To read more or decline the use of some cookies please see our Cookie Settings.