Tests library for Bot Framework dialogs using XUnit and Objectivity Test Stories.
This project is still a work in progress, all contributions from your site will be very desirable!
You can install the package using the nuget:
Install-Package Objectivity.Bot.Tests.Stories.Xunit
At the moment test base classes are permitted only for dialogs returning object type. Story recorder used in this library does not allow to recognize user identity during conversation test.
To develop a unit test for a dialog, create new test class inheriting from Objectivity.Bot.Tests.Stories.Xunit.DialogUnitTestBase<T>
class, providing your dialog Type as generic parameter. Then for each test please go through the following steps:
- Record a story
- Rewind
- Play (assert)
Example:
public class EchoDialogTests : DialogUnitTestBase<EchoDialog>
{
[Fact]
public async Task HelloTest()
{
var story = StoryRecorder
.Record()
.User.Says("Hello")
.Bot.Says("You said Hello")
.Rewind();
await this.Play(story);
}
}
You can also define various dialog finish scenarios.
The example below assumes the Dialog calls context.Done()
after bot posts first reply.
public class MyDialogTests : DialogUnitTestBase<MyDialog>
{
[Fact]
public async Task HelloTest()
{
var story = StoryRecorder
.Record()
.User.Says("Hi")
.Bot.Says("Good bye")
.DialogDone();
await this.Play(story);
}
}
The example below assumes the Dialog calls context.Done(true)
after bot posts first reply.
public class MyDialogTests : DialogUnitTestBase<MyDialog>
{
[Fact]
public async Task HelloTest()
{
var story = StoryRecorder
.Record()
.User.Says("Hi")
.Bot.Says("Good bye")
.DialogDoneWithResult<bool>(result => result == true);
await this.Play(story);
}
}
The example below assumes the Dialog calls context.Fail(ex)
with any kind of exception after first user sentence.
public class MyDialogTests : DialogUnitTestBase<MyDialog>
{
[Fact]
public async Task HelloTest()
{
var story = StoryRecorder
.Record()
.Bot.Says("Type a number:")
.User.Says("Ok")
.DialogFailed();
await this.Play(story);
}
}
The example below assumes the Dialog calls context.Fail(ex)
with specific kind of exception after first user sentence.
public class MyDialogTests : DialogUnitTestBase<MyDialog>
{
[Fact]
public async Task HelloTest()
{
var story = StoryRecorder
.Record()
.Bot.Says("Type a number:")
.User.Says("Ok")
.DialogFailedWithExceptionOfType<FormatException>();
await this.Play(story);
}
}
To develop a unit test for a LUIS dialog (inheriting LuisDialog<object>
class), create new test class inheriting from Objectivity.Bot.Tests.Stories.Xunit.LuisDialogUnitTestBase<T>
class, providing your dialog Type as generic parameter. Then for each test please go through the following steps:
- Register utterance (for intent test)
- Record a story
- Rewind
- Play (assert)
Example:
public class PizzaOrderDialogTests : LuisDialogUnitTestBase<EchoDialog>
{
[Fact]
public async Task HelloTest()
{
var story = StoryRecorder
.Record()
.User.Says("Hello")
.Bot.Says("You said Hello")
.Rewind();
await this.Play(story);
}
}
If your dialog requires some dependencies injected using Autofac, you can provide them by overloading RegisterAdditionalTypes
protected method. Example:
protected override void RegisterAdditionalTypes(ContainerBuilder builder)
{
builder.RegisterType<EchoService>().As<IEchoService>();
}