Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Botkit dialog test client #1815

Merged
merged 3 commits into from
Nov 1, 2019
Merged

Botkit dialog test client #1815

merged 3 commits into from
Nov 1, 2019

Conversation

qwertyuu
Copy link
Contributor

Hello! Our team is starting to love the library you are developing. Since we are starting to consider writing tests to make sure our botkit bots are behaving as expected.

Since we could not find a specific way to test the library, I went ahead and searched around the web for a way to test botbuilder bots. Microsoft seems to provide a way to do it: https://github.com/microsoft/botbuilder-js/blob/master/libraries/botbuilder-testing/src/dialogTestClient.ts

So I went ahead and brought that code back into Botkit's code base and adapted it to take a Botkit instance and a thread name to test. I have provided an example test file showing how to use the test client in the PR.

This will be immensely useful for both our team and the whole botkit community.

@msftclas
Copy link

msftclas commented Sep 19, 2019

CLA assistant check
All CLA requirements met.

@qwertyuu
Copy link
Contributor Author

qwertyuu commented Sep 19, 2019

By the way, I don't think tests/Core.tests.ts runs when executing npm test so I doubt my example test also runs in the CI. I might be mistaken though, I have no idea how lerna works.

@etiennellipse
Copy link
Contributor

etiennellipse commented Oct 1, 2019

I got it running through lerna. I added the test script to botkit's package.json, and modified the core test so that it does not hang the process. (see 41cf410)

People can now add coverage when fixing issues on the dialog engine, which I believe is a great enhancement.

@ianfixes
Copy link

Can you add some documentation for how this code can be leveraged to write tests of a bot?

@etiennellipse
Copy link
Contributor

@ianfixes Check the packages/botkit/tests/Dialog.tests.js file, that is the starting point. Actually, this addition allows a much better test coverage of the Botkit project itself in the future since it makes dialog testing possible in isolation.

@ianfixes
Copy link

In this example:

    it('should follow a dialog', async function () {
        const introDialog = new BotkitConversation('introduction', bot);
        introDialog.ask({
            text: 'You can say Ok',
            quick_replies: [{
                title: 'Ok',
                payload: 'Ok'
            }],
        }, [], 'continue');
        bot.addDialog(introDialog);

        // set up a test client
        const client = new BotkitTestClient('test', bot, 'introduction');

        // Get details for the reply
        const quickreply_reply = await client.sendActivity();
        assert(quickreply_reply.text === 'You can say Ok');
        assert(quickreply_reply.channelData.quick_replies[0].title === 'Ok');
    });

It looks like you're creating the bot immediately before testing it. In normal use, I'd be instantiating my own bot-under-test somehow, and the test would simply have a-priori knowledge that there was a skill called 'introduction'... right?

@qwertyuu
Copy link
Contributor Author

@ianfixes Yes. The test I wrote is "self-contained" as an example. The dialog should not be known to the test, other than its name (introduction here) and its expected outcomes.

@benbrown benbrown self-assigned this Oct 24, 2019
@benbrown
Copy link
Contributor

Thank you for doing this work. I'll work to get it included in the next release.

@benbrown benbrown added this to the 4.6 milestone Oct 24, 2019
@benbrown
Copy link
Contributor

This is super awesome, btw.

I am using this testing tool to validate the 4.6 changes.

Hooray!

@benbrown benbrown merged commit 41cf410 into howdyai:master Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants