botbuilder-js/libraries/botbuilder-testing
Joel Mut 8b45b7522f
chore: [#3518] Remove public access modifier from generators, declarative, testing and schema (#4214)
* Remove 'public' access modifier from generator-botbuilder folder

* Remove 'public' access modifier from botbuilder-dialogs-declarative folder

* Remove 'public' access modifier from botbuilder-testing folder

* Remove 'public' access modifier from botframework-schema folder
2022-06-15 15:43:58 -05:00
..
etc chore: add test:compat to CI tests (#3691) 2021-05-19 15:21:39 -07:00
src chore: [#3518] Remove public access modifier from generators, declarative, testing and schema (#4214) 2022-06-15 15:43:58 -05:00
tests Add additional eslint rules for test files (#3447) 2021-03-31 16:33:25 -07:00
.eslintrc.json fix: eslint settings, lint errors (#3348) 2021-03-05 13:35:12 -08:00
.gitignore first import of dialog test client pacakge 2019-06-13 11:59:42 -05:00
LICENSE Add LICENCE to libraries (#4169) 2022-03-21 17:43:03 -04:00
README.md DialogTestClient updates (#1034) 2019-07-03 13:32:18 -07:00
api-extractor.json chore: add test:compat to CI tests (#3691) 2021-05-19 15:21:39 -07:00
package.json chore: add missing packages to consumer test (#3737) 2021-06-22 09:29:11 -07:00
tsconfig.json monorepo: ci, lint, package.json overhaul (#3058) 2020-11-12 11:58:42 -08:00

README.md

Bot Framework Testing Utilities

This library contains some helper classes useful for testing bots built with Bot Framework.

Install

First, install this library from npm:

npm install --save botbuilder-testing

Unit Tests for Dialogs

DialogTestClient provides a mechanism for testing dialogs outside of a bot, and without having to set up a working adapter. This class can be used to write unit tests for dialogs that test responses on a step-by-step basis. Any dialog built with botbuilder-dialogs should work.

Use the DialogTestClient to drive unit tests of your dialogs.

To create a test client:

const client = new DialogTestClient('test', dialog_to_test, dialog_options, OptionalMiddlewares);

To "send messages" through the dialog:

let reply = await client.sendActivity('test');

To check for additional messages:

reply = client.getNextReply();

Here is a sample unit test using assert:

const { DialogTestClient, DialogTestLogger } = require('botbuilder-testing');
const assert = require('assert');

const my_dialog = new SomeDialog();
const options = { ... dialog options ... };

// set up a test client with a logger middleware that logs messages in and out
const client = new DialogTestClient('test', my_dialog, options, [new DialogTestLogger()]);

// send a test message, catch the reply
let reply = await client.sendActivity('hello');
assert.strictEqual(reply.text, 'hello yourself', 'first message was wrong');
// expecting 2 messages in a row?
reply = client.getNextReply();
assert.strictEqual(reply.text, 'second message', 'second message as wrong');

// test end state
assert.strictEqual(client.dialogTurnResult.status, 'empty', 'dialog is not empty');

Additional examples are available here

DialogTestLogger

This additional helper class will cause the messages in your dialog to be logged to the console. By default, the transcript will be logged with the mocha-logger package. You may also provide your own logger:

const testlogger = new DialogTestLogger(console);