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
550
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
390
Other Decks in Programming
See All in Programming
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
180
「ちょっと古いから」って避けてた技術書、今だからこそ読もう
mottyzzz
8
5.1k
LLMとPlaywright/reg-suitを活用した jQueryリファクタリングの実際
kinocoboy2
4
680
What's new in Spring Modulith?
olivergierke
1
110
Go Conference 2025: Goで体感するMultipath TCP ― Go 1.24 時代の MPTCP Listener を理解する
takehaya
7
1.6k
Breaking Up with Big ViewModels — Without Breaking Your Architecture (droidcon Berlin 2025)
steliosf
PRO
1
350
CI_CD「健康診断」のススメ。現場でのボトルネック特定から、健康診断を通じた組織的な改善手法
teamlab
PRO
0
190
大規模アプリのDIフレームワーク刷新戦略 ~過去最大規模の並行開発を止めずにアプリ全体に導入するまで~
mot_techtalk
0
410
Domain-centric? Why Hexagonal, Onion, and Clean Architecture Are Answers to the Wrong Question
olivergierke
2
650
ソフトウェア設計の実践的な考え方
masuda220
PRO
3
510
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
120
エンジニアとして高みを目指す、 利益を生み出す設計の考え方 / design-for-profit
minodriven
23
12k
Featured
See All Featured
Gamification - CAS2011
davidbonilla
81
5.5k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
114
20k
Documentation Writing (for coders)
carmenintech
75
5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
970
KATA
mclloyd
32
15k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Music & Morning Musume
bryan
46
6.8k
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
ご清聴ありがとうございました