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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
HeRo
July 17, 2018
Programming
580
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Alexaスキルのテスト
Alexaスキルのローカルテストについて
Jest + Virtual-Alexa
2018/07/17 Meguro.dev で発表
HeRo
July 17, 2018
More Decks by HeRo
See All by HeRo
いこレポでのWorkbox導入事例 @PWA Night #7
hero
0
1.9k
Alexaスキルアワード2018_いこーよのおでかけナビ
hero
0
420
Other Decks in Programming
See All in Programming
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.7k
Agentic UI
manfredsteyer
PRO
0
220
自作OSでスライド発表する
uyuki234
1
3.6k
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
990
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
200
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
130
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
160
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
240
AIエージェントで 変わるAndroid開発環境
takahirom
1
390
どこまでゆるくて許されるのか
tk3fftk
0
300
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
430
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
440
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.9k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
YesSQL, Process and Tooling at Scale
rocio
174
15k
WCS-LA-2024
lcolladotor
0
670
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
260
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
The World Runs on Bad Software
bkeepers
PRO
72
12k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
410
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
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
ご清聴ありがとうございました