Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Alexaスキルのテスト
Search
HeRo
July 17, 2018
Programming
0
510
Alexaスキルのテスト
Alexaスキルのローカルテストについて
Jest + Virtual-Alexa
2018/07/17 Meguro.dev で発表
HeRo
July 17, 2018
Tweet
Share
More Decks by HeRo
See All by HeRo
いこレポでのWorkbox導入事例 @PWA Night #7
hero
0
1.7k
Alexaスキルアワード2018_いこーよのおでかけナビ
hero
0
370
Other Decks in Programming
See All in Programming
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
480
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
1
140
Introduction to kotlinx.rpc
arawn
0
630
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
5
730
時計仕掛けのCompose
mkeeda
1
280
AHC041解説
terryu16
0
590
ファインディの テックブログ爆誕までの軌跡
starfish719
2
1.1k
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
200
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
770
iOSエンジニアから始める visionOS アプリ開発
nao_randd
3
120
Unity Android XR入門
sakutama_11
0
140
Writing documentation can be fun with plugin system
okuramasafumi
0
120
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Speed Design
sergeychernyshev
25
780
Statistics for Hackers
jakevdp
797
220k
Building Adaptive Systems
keathley
40
2.4k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.4k
Gamification - CAS2011
davidbonilla
80
5.1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
31
2.1k
Become a Pro
speakerdeck
PRO
26
5.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Designing for humans not robots
tammielis
250
25k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Transcript
Alexaスキルの テスト
自己紹介 Morishita Hiromitsu ⊙ Webエンジニア ⊙ アクトインディ所属 ⊙ 主にRoRで開発しています。 ⊙
担当サービス「いこレポ」 ◦ インフラからフロントエンドまでまるっとサポート
Alexaスキル の 開発環境 (今日の前提条件) ⊙ バックエンドはLambda (Node.js) ⊙ Typescriptで実装 ⊙
Serverless Framework を使ってます(スミマセン)
“ Alexaスキルのテストって どうする?
⊙ Alexaコンソールに含まれる ⊙ E2Eテストができる ⊙ このサイクルの繰り返しが辛い Alexa シミュレータ 実装 デプ
ロイ 発話 結果 確認
ここがつらい ⊙ ビルド+デプロイに時間がかかる ⊙ 実行後の確認が面倒 ◦ どこでエラーが発生したのかわかりにくい ◦ Clowd Watch
Logsでデバッグログを探すのが… ⊙ UIの操作も面倒 実装 デプ ロイ 発話 結果 確認
“ なんとかしたいですよね?
テスト しやすい 実装 スキル用のLambdaの処理のパターン 1. SlotやAttributesの取り出し 2. それらの値に基づくspeech textの生成 Alexaプロトコル
の処理 ビジネスロジック 分離 ↑この部分は AlexaともLambdaとも無関係 Slot、Attributesの値 SpeechText
でも、 E2Eテストも したい
Lambdaの ローカル 実行 Serverless Frameworkのinvoke localで ローカル実行 sls invoke local
-f handler -p input.json ⊙ webpack pluginで実行前にTSをトランスパイル ⊙ input.json はAlexaシミュレータのJSON入力をファイ ルに保存したもの
VSCodeのデ バッガで実 行 { "type": "node", "request": "launch", "name": "LaunchRequest",
"program": "${workspaceRoot}/node_modules/.bin/sls", "cwd": "${workspaceRoot}", "args": [ "invoke", "local", "-f", "handler", "-p", "input.json"], "outFiles": [ "${workspaceRoot}/.webpack/service/*.js" ], "sourceMaps": true } 次の設定をlaunch.jsonに追加してデバッ グから実行するとブレークポイントで止め られる
デバッグ しやすくは なったが… Serverless invoke localでの実行 は手軽だが… ⊙ 結局、人力で結果確認 ⊙
CIに組み込みにくい ⊙ 対話モデルはテストできない の? Alexa固有 の処理 ビジネスロジック 対話 モデル lambda
Jest with Virtual-Alexa Jest JSのテストフレームワーク Virtual-Alexa Alexaのテストライブラリ
Jest について もう少し 詳しく ⊙ Facebook社製 ⊙ オールインワン ◦ テストランナー
◦ アノテーション ◦ モック ◦ コードカバレッジ ⊙ Reactやってるところでよく使わ れる?
Virtual-Alexa を もう少し詳 しく ⊙ bespoken社製 ⊙ 発話モデルを読み込んでテストする ⊙ 発話、インテント指定でテスト可能
⊙ DaynamoDB、AddressAPIのモックも提供 ⊙ 公式ドキュメント https://bespoken.github.io/virtual-alexa/api/
テスト対象 の インテント FeelingIntent 今日の気分はいかがですか? 今日の気分は絶好調。 素晴らしい! 張り切っていきましょう!
FeelingIntent スロットを 含むものと 含まないもの がある
カスタム スロット IDを設定
テスト対象 コード const FeelingIntentHandler: RequestHandler = { canHandle{省略} handle(handlerInput: HandlerInput):
Response { const request = handlerInput.requestEnvelope.request as IntentRequest; const slot = request.intent.slots && request.intent.slots.feeling; let speech: string; const reprompt: string = new Speech().say("今日の気分を教えてください ").ssml(); if (slot.value) { const feelingId = slot.resolutions.resolutionsPerAuthority[0].values[0].value.id; switch (feelingId) { case "0": speech = new Speech().say("まあ、元気だして。くよくよせずに行きましょう。 ").ssml(); break; case "5": speech = new Speech().say("いつもどおりで行きましょう。 ").ssml(); break; case "8": speech = new Speech().say("そんなときは思い切って行動しましょう。 ").ssml(); break; case "10": speech = new Speech().emphasis("strong", "素晴らしい !").say("張り切っていきましょう! ").ssml(); break; } } else { speech = "そんな日もありますよね "; } return handlerInput.responseBuilder.speak(speech).reprompt(reprompt).getResponse(); },}; export default FeelingIntentHandler; IDで処理を分岐
テストコード import {SkillResponse, VirtualAlexa} from "virtual-alexa"; import { handler }
from "../../index"; const alexa = VirtualAlexa.Builder() .handler(handler) .interactionModelFile("./interaction_models/model_ja-JP.json") .create(); describe("FeelingIntent", () => { it ("よくわかんない", async () => { const response = await alexa.utter("よくわかんない") as SkillResponse; const outputSpeech = response.response.outputSpeech.ssml; expect(outputSpeech).toContain("そんな日もありますよね"); }); it ("気分は絶好調", async () => { const response = await alexa.intend("FeelingIntent", { feeling: "絶好調"}) as SkillResponse; const outputSpeech = response.response.outputSpeech.ssml; expect(outputSpeech).toContain("素晴らしい!"); }); }); スロットを含まないものは 発話でテスト可能 スロットを含むものは インテント名とスロットの値 でテスト テスト対象のハンドラ 発話モデルのJSON ask-cliで取得
デバッガも 使える
lanuch.json はこんな 感じ { "version": "0.2.0", "configurations": [ { "type":
"node", "request": "launch", "name": "Debug Tests", "program": "${workspaceRoot}/node_modules/.bin/jest", "cwd": "${workspaceRoot}", "args": [ "--i", "--config", "jest.json" ], "sourceMaps": true }, }
まとめ ⊙ Jest+Virtual-AlexaでAlexaスキ ルも自動テスト可能 ◦ 発話モデルもLambdaも ⊙ VSCodeを使えばデバッガを使 うのも簡単 ⊙
でも、Alexaがどう聞き取るか はテストできないので 実機テストも重要
おまけ 今日紹介したテストを含む Serverless Frameworkの テンプレートを公開しました。 https://github.com/HeRoMo/serv erless-aws-alexa-ts
ご清聴ありがとうございました