我正在开发node中的Alexa技能,我想知道如何对代码进行单元测试。我使用的是亚马逊发布的alexa sdk。
我已经找到了许多库来实现这一点,但它们似乎是在alexa sdk可用之前开发的。
提前谢谢。
发布于 2017-02-13 10:50:41
我们专门为实现Alexa技能的简单单元测试和功能测试而构建了Alexa仿真器:
http://docs.bespoken.tools/en/latest/tutorials/tutorial_bst_emulator_nodejs/
使用它,您可以像这样进行调用:
alexa.launched(function (error, response) {
alexa.spoken('About the podcast', function (error, response) {
assert.equal(response.response.outputSpeech.ssml, '<speak> Some SSML </speak>');
done();
});
});这个测试代码模仿用户启动技能并说“关于播客”。这些交互将自动转换为正确的Alexa JSON请求,然后将其发送到您的技能代码。
您还可以创建更复杂的单元测试,这些测试依赖于在交互过程中模拟Alexa设备的内部状态。这些将在本教程中进行介绍。
发布于 2017-12-05 18:13:26
我正在使用alexa-skill-test-framework和mocha来生成alexa intent json。支持DynamoDB、SQS、Lambda等服务的localstack,可以在本地PC上设置亚马逊网络服务
发布于 2018-02-23 01:13:12
lex-bot-tester是一个框架和工具,用于为Amazon Alexa和Lex创建会话测试。
它使用现有的SMAPI来处理Alexa,而不是使用该技能的模拟版本。
测试可以手动创建,也可以由包含的名为urutu的工具自动生成。目前,代码生成是python,但Skill实现可以是任何支持的语言。
从命令行与技能交互后,定义对话,生成的代码如下所示
#! /usr/bin/env python
import sys
import unittest
from lex_bot_tester.aws.alexa.alexaskilltest import AlexaSkillTest
verbose = True
class GeneratedTests(AlexaSkillTest):
def test_book_my_trip_reserve_car(self):
"""
Test generated by urutu on 2018-02-21 01:24:51
"""
skill_name = 'BookMyTripSkill'
intent = 'BookCar'
conversation = [{'slot': None, 'text': 'ask book my trip to reserve a car', 'prompt': None},
{'slot': 'CarType', 'text': 'midsize',
'prompt': 'What type of car would you like to rent, Our most popular options are economy, midsize, and luxury'},
{'slot': 'PickUpCity', 'text': 'vancouver',
'prompt': 'In what city do you need to rent a car?'},
{'slot': 'PickUpDate', 'text': 'tomorrow',
'prompt': 'What day do you want to start your rental?'},
{'slot': 'ReturnDate', 'text': 'next week',
'prompt': 'What day do you want to return the car?'},
{'slot': 'DriverAge', 'text': '25', 'prompt': 'How old is the driver for this rental?'}]
simulation_result = self.conversation_text(skill_name, intent, conversation, verbose=verbose)
self.assertSimulationResultIsCorrect(simulation_result, verbose=verbose)
if __name__ == '__main__':
unittest.main()在Testing Alexa Skills — Autogenerated tests上有更详细的解释和一些视频。
https://stackoverflow.com/questions/42190976
复制相似问题