Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Alexaスキルのテスト
Search
HeRo
July 17, 2018
Programming
0
560
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.8k
Alexaスキルアワード2018_いこーよのおでかけナビ
hero
0
400
Other Decks in Programming
See All in Programming
ID管理機能開発の裏側 高速にSaaS連携を実現したチームのAI活用編
atzzcokek
0
230
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
410
sbt 2
xuwei_k
0
300
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
7.3k
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
190
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
130
AIコーディングエージェント(NotebookLM)
kondai24
0
200
Go コードベースの構成と AI コンテキスト定義
andpad
0
130
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
340
ゲームの物理 剛体編
fadis
0
350
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
38
26k
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
270
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
A Tale of Four Properties
chriscoyier
162
23k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Faster Mobile Websites
deanohume
310
31k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
BBQ
matthewcrist
89
9.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
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
ご清聴ありがとうございました