我们正在使用 Amazon Lex 构建一个机器人。随着机器人的功能不断增长,我们需要一种方法来确保机器人在我们引入新更改时继续工作,但是手动执行此操作变得非常昂贵。我们无法在 Amazon Lex SDK 工具中找到为 Lex 机器人创建自动化测试的工具。是否有一些框架或工具可以帮助解决这个问题并与 Node.js 一起使用?
问问题
396 次
2 回答
3
我们面临同样的问题。环顾四周后,我认为构建一些简单的工具来为 Lex 运行自动化测试会更容易。请记住,此解决方案要求您首先在 Amazon Lex 中部署机器人,因此它不是创建单元测试,而更像是功能测试。
基本上我们所做的是创建一个像这样的简单库,它使用 Amazon SDK 向机器人发送文本:
let uuid = require('uuid/v4'),
aws = require('aws-sdk');
let config = {
awsAccount: process.env.AWS_ACCOUNT,
awsAccessKey: process.env.AWS_ACCESS_KEY_ID,
awsAccessKeySecret: process.env.AWS_SECRET_ACCESS_KEY,
awsRegion: process.env.AWS_DEFAULT_REGION,
botName: 'BotName',
botAlias: 'Dev'
};
let lex;
exports.config = config;
exports.initConfig = function() {
aws.config.update({
credentials: new aws.Credentials(config.awsAccessKey, config.awsAccessKeySecret),
region: config.awsRegion
});
lex = new aws.LexRuntime();
};
exports.speak = async function(userId, previousResponse, text) {
let res = await lex.postText({
botAlias: config.botAlias,
botName: config.botName,
inputText: text,
userId: userId,
requestAttributes: previousResponse ? previousResponse.requestAttributes : {},
sessionAttributes: previousResponse ? previousResponse.sessionAttributes : {}
}).promise();
return res;
};
exports.generateUserId = function() {
return uuid();
};
然后你可以使用像 Mocha 这样的工具来创建这样的测试:
let assert = require('chai').assert,
utils = require('./utils'); // this is the library above
utils.initConfig();
describe('your conversation name', function() {
it('conversation path 1', async function() {
let userId = utils.generateUserId();
let res = await utils.speak(userId, null, 'init message');
assert.equal(res.slots.slot1, 'val1'); // check slot value
assert.include(res.message, 'words included'); // check response from bot
res = await utils.speak(userId, res, 'send more messages');
assert.equal(res.slots.slot2, 'val2'); // check another slot value
assert.include(res.message, 'another words included'); // check response from bot
});
});
同样,这不是单元测试,而是功能测试。
注意:我之前看到此答案已被删除,因为它与另一个答案相同。我正在回答两个问题并混合了答案,但我已经更改了另一个答案,所以这是完全不同的。所以我再发一次。
于 2019-07-26T08:13:49.610 回答
0
Botium为聊天机器人提供自动化测试,Amazon Lex 是支持的平台之一。Botium Core 是开源的,可在 Github 上使用 - 它允许您使用多个 CLI 工具和 Javascript 测试运行程序运行自动化测试(请参阅Botium 绑定)。 Botium Box提供了一个漂亮的用户界面和一整套测试聊天机器人所需的所有东西 - 社区版可用。
于 2020-05-15T10:41:12.533 回答