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.
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.