Reputation: 109
I looking for an example to write unit test cases for bot builder dialogs for V4 Sdk. I came across a blog but that is for v3 (https://www.microsoft.com/developerblog/2017/01/20/unit-testing-for-bot-applications/) Are there any examples or patterns to follow if I need dialogs to be unit tested for conversation flow? I have looked at the option of using new emulator and transcript files but, that is more for about functional flow and designers to look at mock ups where dialogs are not really tested.
I came across Test Adapter but trying to find how can I run the example form the page with my local bot instance.
Upvotes: 0
Views: 860
Reputation: 1204
You can find examples of both C# and TS versions of unit tests for the Enterprise Bot template.
It's written in mocha, which is the same testing framework used to write unit tests for the botbuilder-js repo itself.
Here's a little snippet of one the Intro Card
test in the Main
dialog.
describe("Intro Card", function () {
it("Send conversationUpdate and verify card is received", function (done) {
const testAdapter = botTestBase.getTestAdapter();
const flow = testAdapter
.send({
type: "conversationUpdate",
membersAdded: [
{
id: "1",
name: "Bot"
}
],
channelId: "emulator",
recipient: {
id: "1"
}
})
.assertReply(function (activity, description) {
assert.equal(activity.attachments[0].contentType, 'application/vnd.microsoft.card.adaptive');
assert.deepEqual(activity.attachments[0].content, introJson);
})
testNock.resolveWithMocks('mainDialog_introCard_response', done, flow);
});
});
Bear in mind that the template team is actively building both Virtual Assistant and Enterprise Bot, so it's possible that the pattern may change, but this is what they have published right now :)
Upvotes: 2