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

Is this framework for unit test only? #48

Closed
pradgnyak opened this issue Dec 19, 2017 · 14 comments
Closed

Is this framework for unit test only? #48

pradgnyak opened this issue Dec 19, 2017 · 14 comments
Labels

Comments

@pradgnyak
Copy link

This doesn't test actual apps?

@microsoftly
Copy link
Owner

@pradgnyak this can test any bot in any environment.

I'm not sure what your question is. I'd be happy to give more insight if you want it

@pradgnyak
Copy link
Author

pradgnyak commented Dec 20, 2017

I have installed the package and set the

Config File

{
    "defaultAddress": {
        "id": "XXXXXXX",
        "channelId": "console",
        "bot": {
            "id": "XXXXXX:XXXXXX",
            "name": "mwtest_bot"
        },
        "user": {
            "id": "XXXXX:XXXXX",
            "name": "mwtest"
        },
        "conversation": {
            "id": "XXX;XXXX;XXX",
            "name": "directmessage"
        }
    }
}

My Test File

var botbuilder = require('botbuilder');
var IAddress = require('botbuilder').IAddress;
var IMessage = require('botbuilder').IMessage;
var Message = require('botbuilder').Message;
var Prompts = require('botbuilder').Prompts;
var Session = require('botbuilder').Session;
var UniversalBot = require('botbuilder').UniversalBot;
var botTester = require('bot-tester');

// import { IAddress, IMessage, Message, Prompts, Session, UniversalBot } from 'botbuilder';
require('chai');
require('mocha');
var expect = require('chai').describe;
// import { BotTester, TestConnector } from 'bot-tester';
// import { getAdaptiveCard, getAdaptiveCardAttachment, getAdaptiveCardMessage } from './adaptiveCardProvider';
// import { read } from 'fs';

const connector = new botTester.TestConnector();

describe('BotTester', () => {
    var bot;

    beforeEach(() => {
        // bot = new UniversalBot(connector);
        // var connector = new botbuilder.ChatConnector({
        //     appId: 'XXXXXXX',
        //     appPassword:XX'
        // })
        var connector = new botTester.TestConnector();
        // connector.listen();
        bot = new UniversalBot(connector);
        console.log(bot);
    });

    it('can handle a single response', () => {
        bot.dialog('/', (session) => {
            session.send('hi!');
        });

        var bt = new botTester.BotTester(bot)
            .sendMessageToBot('Hola!', 'hi!');

        return bt.runTest();
    });
});

Result

> mocha test1


  0 passing (37ms)
  1 failing

  1) BotTester
       can handle a single response:
     Error: the string "timedout while waiting to receive [\n  \"hi!\"\n]" was thrown, throw an Error :)
      at tryCatcher (node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:512:31)
      at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:569:18)
      at Promise._settlePromise0 (node_modules/bluebird/js/release/promise.js:614:10)
      at Promise._settlePromises (node_modules/bluebird/js/release/promise.js:689:18)
      at Async._drainQueue (node_modules/bluebird/js/release/async.js:133:16)
      at Async._drainQueues (node_modules/bluebird/js/release/async.js:143:10)
      at Immediate.Async.drainQueues [as _onImmediate] (node_modules/bluebird/js/release/async.js:17:14)

@microsoftly
Copy link
Owner

Could you please format your submission and tidy up the code a tad? I'm having some trouble following what you did

@microsoftly
Copy link
Owner

what version of the bot-tester framework are you using? Are you running with Node or typescript?

@pradgnyak
Copy link
Author

Updated the comment.
I am running with Node,
├─┬ bot-tester@3.3.0
│ ├── botbuilder@3.13.1 deduped
├─┬ botbuilder@3.13.1

@microsoftly
Copy link
Owner

microsoftly commented Dec 20, 2017

Great catch. Looks like something is wrong with the timeout when it's not set in the config file. I'll have another release out soon to resolve the issue. In the meantime, let me know if throwing in a timeout: <some number> to the config file resolves the issue on your end (I'd recommend 500+, its in ms)

@pradgnyak
Copy link
Author

I had tried it with timeout too but it resulted in same error.

@microsoftly
Copy link
Owner

here's the file I'm running (same as yours, fluff removed)

var botTester = require('bot-tester');
var botbuilder = require('botbuilder');

var UniversalBot = botbuilder.UniversalBot;

require('chai');
require('mocha');

const connector = new botTester.TestConnector();

describe('BotTester', () => {
    var bot;

    beforeEach(() => {
        var connector = new botTester.TestConnector();
        bot = new UniversalBot(connector);
    });

    it('can handle a single response', () => {
        bot.dialog('/', (session) => {
            session.send('hi!');
        });

        return new botTester.BotTester(bot)
            .sendMessageToBot('Hola!', 'hi!')
            .runTest();
    });
});

and the bot-tester.json with it passing

{
    "timeout":1000,
    "defaultAddress": {
        "id": "XXXXXXX",
        "channelId": "console",
        "bot": {
            "id": "XXXXXX:XXXXXX",
            "name": "mwtest_bot"
        },
        "user": {
            "id": "XXXXX:XXXXX",
            "name": "mwtest"
        },
        "conversation": {
            "id": "XXX;XXXX;XXX",
            "name": "directmessage"
        }
    }
}

and the bot-tester.json with it failing

{
    "defaultAddress": {
        "id": "XXXXXXX",
        "channelId": "console",
        "bot": {
            "id": "XXXXXX:XXXXXX",
            "name": "mwtest_bot"
        },
        "user": {
            "id": "XXXXX:XXXXX",
            "name": "mwtest"
        },
        "conversation": {
            "id": "XXX;XXXX;XXX",
            "name": "directmessage"
        }
    }
}

The error message I'm is exactly the same as the one you're getting:
Error: the string "timedout while waiting to receive [\n \"hi!\"\n]" was thrown, throw an Error :)

@pradgnyak
Copy link
Author

pradgnyak commented Dec 20, 2017

Test passes after adding the timeout, but I do not see the interaction on my slack. Where is this request going?

@microsoftly
Copy link
Owner

When you say you don't see the interaction on your slack, what are you expecting to see?

botTester.sendMessageToBot mocks any incoming message to the bot. All outgoing messages seen but not intercepted. If you use the ConsoleConnector instead of the TestConnector you will actually see messages that the bot responds with.

The behavior I would expect is only having bot responses being seen on the slack channel. I personally have not tested with a bot out in the wild.

I'm unsure why the messages would not be sent properly. Is no request being sent out? Can you take a snapshot of the messages you're attempting to send?

Try attaching an outgoing listener and see what's actually being sent. Also try with the ConsoleConnector to see if the messages are printed to the console

@pradgnyak
Copy link
Author

My test case is
1: Slack user says 'hi'
2. Bot responds with options to the user on Slack
How can I simulate this using bot-tester?

Is there a detailed documentation of all the available methods?

@microsoftly
Copy link
Owner

microsoftly commented Dec 21, 2017

I think the answer you're looking for is:

botTester.sendMessageToBot can take in a string, regex, or an IMessage. To mock the slack channel, you would need to create an IMessage with the same structure that would be seen from a message originating from slack. Currently, there is no built in support for that. You would need to home bake the IMessage structure yourself. I'm guessing it would just be part of the address field. If you're unsure what it would look like, I'd recommend putting in a receive listener and inspecting the structure through a message you manually send through slack.


A possible feature request could be adding functions like sendSlackMessageToBot, though that would take some thought on how to make it work cleanly.


The detailed docs for sendMessageToBot documentation can be found in the BotTester Framework Docs. It gives a full type definitions along with any typedocs associated with methods, fields, or classes.


As a final note: unless your bot acts differently for messages from slack than it would from other channels, I would recommend you reconsider how you're testing or viewing your testing altogether. This framework is can test a bot in any environment, but only simulate receiving messages (I'm still unsure if it would actually send them out seeing because outgoing message's destination channel shouldn't exist).

tldr; as of this writing, this is good for unit to integration/component level testing for the bot itself, though you can test in any environment. You can choose to mock external dependencies/requests or let them through to a live system, but the messages to the bot will always be mocked/simulated

@microsoftly
Copy link
Owner

@pradgnyak let me know if this helped or there is more clarity you need. I'd be happy to work with you and extend the existing functionality to suit your needs

@pradgnyak
Copy link
Author

Thanks a lot, we have decided to use slack API's for testing since they are exposed and can be used for end to end testing in real environment. If we change our approach I will get in touch with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants