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
Cache Me If You Can
ryunen344
2
670
Testing Trophyは叫ばない
toms74209200
0
860
Amazon RDS 向けに提供されている MCP Server と仕組みを調べてみた/jawsug-okayama-2025-aurora-mcp
takahashiikki
1
110
print("Hello, World")
eddie
2
530
今だからこそ入門する Server-Sent Events (SSE)
nearme_tech
PRO
1
110
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
260
為你自己學 Python - 冷知識篇
eddie
1
350
Navigating Dependency Injection with Metro
zacsweers
3
240
Flutter with Dart MCP: All You Need - 박제창 2025 I/O Extended Busan
itsmedreamwalker
0
150
機能追加とリーダー業務の類似性
rinchoku
2
1.2k
Tool Catalog Agent for Bedrock AgentCore Gateway
licux
6
2.3k
そのAPI、誰のため? Androidライブラリ設計における利用者目線の実践テクニック
mkeeda
2
270
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
328
39k
BBQ
matthewcrist
89
9.8k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.1k
Six Lessons from altMBA
skipperchong
28
4k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.9k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
How to Ace a Technical Interview
jacobian
279
23k
Building Applications with DynamoDB
mza
96
6.6k
A Modern Web Designer's Workflow
chriscoyier
696
190k
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
ご清聴ありがとうございました