Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Agentic AI 時代のテスト手法: Kiro とはじめるプロパティベーステスト (AW...

Agentic AI 時代のテスト手法: Kiro とはじめるプロパティベーステスト (AWS Summit Japan 2026 | DEV212)

Avatar for Hiroki Yamazaki

Hiroki Yamazaki

July 02, 2026

More Decks by Hiroki Yamazaki

Other Decks in Technology

Transcript

  1. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. D E V 2 1 2 | D E V E L O P E R S O N L I V E ⼭崎 宏紀 Agentic AI 時代のテスト⼿法: Kiro とはじめるプロパティベーステスト Solutions Architect, Amazon Web Services Japan G.K.
  2. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. アマゾンウェブサービスジャパン合同会社 ISV SaaS ソリューション本部 ソリューションアーキテクト ISV / SaaS 業界のお客様を中⼼にご⽀援 好きな AWS サービス: AWS CDK, AWS Transform custom, Kiro ⼭崎 宏紀 (Hiroki Yamazaki) AWS CDK AWS Transform Kiro
  3. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • 想定する聴講者 • Coding Agent (Kiro, Claude Code, etc.) を利⽤した ソフトウェア開発をされているエンジニア • Coding Agent の書くコードのテストやレビューにお疲れの⽅ • 前提知識 • プログラミングと⾃動テストの基本 • Coding Agent の利⽤経験 • 話すこと • プロパティベーステスト (Property-based testing, PBT) の概要、実践例や使い所 • 話さないこと: Kiro の機能詳細 セッションの聴講にあたって
  4. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 1. Coding Agent 使っている⽅︕ • Kiro, Claude Code, Codex, etc… 2. Kiro を使ったことがある⽅︕ 3. Property-based testing を使ったことがある⽅︕ 質問︕
  5. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • Agentic AI 時代のソフトウェアテストの悩み • Property-based testing/ プロパティベーステスト • Demo: EC サイトでのクーポン割引料⾦計算機能 • プロパティベーステスト Dive Deep • まとめ アジェンダ
  6. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agentic AI 時代のソフトウェアテストの悩み
  7. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • 実装もテストも AI が書くと︖ Agentic AI 時代のソフトウェアテストの役割 Coding Agent テスト対象 テストコード 要求仕様 これこれを 実装して できました︕ テストもしてます︕ (テストケース数だけは 多いけどこのテストほんまに 信頼できるんかな・・・)
  8. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. David Thomas, Andrew Hunt 『達⼈プログラマー 第2版』 p.287-288, 2020 ” あなたがコードを記述し、テストを記述するという場合、 その双⽅に誤った仮定が紛れ込んでしまわないのでしょうか︖” ”あなたの抱く予想を共有していないコンピューターが、あなたのために テストを実施するという代替が適切だと考えています”
  9. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Coding Agent の ” あなたがコードを記述し、テストを記述するという場合、 その双⽅に誤った仮定が紛れ込んでしまわないのでしょうか︖” ”あなたの抱く予想を共有していないコンピューターが、あなたのために テストを実施するという代替が適切だと考えています” Coding Agent のために Hiroki Yamazaki, 2026 Coding Agent が
  10. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Property-based testing (PBT)/ プロパティベーステスト
  11. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 「どのような⼊⼒値を与えても常に同じであるような振る舞い」を 記述するルールを実⾏可能なコード (property) として書き表し、 ⽣成したテストケースによってルールがプログラム内で 守られていることを確認するテスト⼿法 出典:『実践プロパティベーステスト ― PropErとErlang/Elixirではじめよう』 プロパティベーステストとは
  12. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. EBT の例: def test_1_plus_2_equals_3(): assert add(1, 2) == 3 def test_add_zero(): assert add(5, 0) == 5 Example-based testing (EBT) と Property-based testing (PBT) この関数をテストしたい # 2つの整数を⾜すだけの関数。 def add(a: int, b: int) -> int: return a + b PBT の例: # 交換法則: a + b == b + a @given(a=st.integers(), b=st.integers()) def test_commutative(a, b): assert add(a, b) == add(b, a) # 単位元: a + 0 == a @given(a=st.integers()) def test_identity(a): assert add(a, 0) == a ⼊⼒値の⽣成規則 成⽴してほしい “振る舞い”
  13. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. add(a, b) == add(b, a) @given(a=st.integers(), b=st.integers()) 「どのような⼊⼒値を与えても常に同じであるような振る舞い」を 記述するルールを実⾏可能なコード (property) として書き表し、 ⽣成したテストケースによってルールがプログラム内で 守られていることを確認するテスト⼿法 出典:『実践プロパティベーステスト ― PropErとErlang/Elixirではじめよう』 プロパティベーステストとは (再掲)
  14. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 冪等性: 複数回実⾏されても結果が変わらない @given(xs=st.lists(st.integers())) def test_sort_idempotent(xs): assert sorted(sorted(xs)) == sorted(xs) 神託: 別の⾔語やライブラリ、アルゴリズムで 実装された結果を神託 (oracle) として利⽤ @given(xs=st.lists(st.integers(), min_size=1)) def test_very_fast_original_impl(xs): assert original_impl(xs) == naive_impl(xs) よくある プロパティ パターン 他にも 対称性、不変条件、可換性などなど・・・
  15. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Demo: EC サイトでのクーポン割引料⾦計算機能
  16. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • あなたは EC サイトでのクーポン割引料⾦計算機能の実装を担当します • 要求仕様は以下の 3 つです • REQ1. 定額 OFF クーポンと 定率 OFF クーポンが存在する • REQ2. 最終⾦額は⼩数点以下切り捨て、0 円以上に切り上げ • REQ3. 顧客最適性: 複数のクーポンを適⽤する場合、 顧客の⽀払う料⾦が最⼩となる順番に適⽤する • REQ3 の例: 1000 円の書籍を購⼊する • 100 円 OFF クーポンと 10 % OFF クーポンを持っている • → (1000 x 90%) – 100 = 800 円 となるのが最適 • ❌ (1000 - 100) x 90% = 810 円 EC サイトでのクーポン割引料⾦計算機能
  17. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. def floor_and_clamp(amount: Decimal) -> int: return max(0, int(amount)) class TestFloorAndClamp: def test_正の⼩数は切り捨て(self) -> None: assert floor_and_clamp(Decimal("899.1")) == 899 assert floor_and_clamp(Decimal("100.99")) == 100 def test_負の値は0に切り上げ(self) -> None: assert floor_and_clamp(Decimal("-100")) == 0 assert floor_and_clamp(Decimal("-0.5")) == 0 REQ2. 最終⾦額は⼩数点以下切り捨て、 0 円以上に切り上げ を処理する実装 & EBT
  18. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⼀度適⽤しても ⼆度適⽤しても 結果は同じ (はず) @given(amount=st.decimals( min_value=Decimal("-10000"), max_value=Decimal("1000000"), places=4, allow_nan=False, allow_infinity=False, )) @settings(max_examples=200) def test_floor_and_clamp_idempotent(amount: Decimal) -> None: once = floor_and_clamp(amount) twice = floor_and_clamp(Decimal(once)) assert once == twice, ( f"floor_and_clamp が冪等でない: amount={amount}, once={once}, twice={twice}" ) REQ2. の PBT: 冪等性パターン ⼊⼒として与えられる 数値の範囲を定義
  19. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. def apply_coupons(price: int, coupons: list[Coupon]) -> int: total: Decimal = Decimal(price) for c in coupons: total = _apply_one(total, c) return floor_and_clamp(total) クーポンを渡された順番に適⽤する実装 この実装では REQ3 (顧客最適性) が満たされていない 反例: 1000 円の商品, [100 円 OFF, 10% OFF] (再掲) REQ3. 顧客最適性: 複数のクーポン (最⼤5枚) を適⽤する場合、 顧客の⽀払う料⾦が最⼩となる順番に適⽤する クーポン適⽤処理の実装 (バグ⼊り)
  20. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. class TestCouponEBT: def test_パーセントOFFからの定額OFF(self) -> None: """REQ3: %OFF が先の順序で渡すと、たまたま最⼩価格と⼀致する。""" coupons = [ PercentOffCoupon(Decimal("0.1")), AmountOffCoupon(100), ] # (1000 * 0.9) - 100 = 800 → たまたま最適解と⼀致 assert apply_coupons(1000, coupons) == 800 バグを検出できて欲しい・・・が、 通ってしまう EBT の例
  21. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 本番環境向け実装で 計算した⾦額が 最適であることを検証 全ての適⽤順序を O(n!) 通り 試して最⼩値を探す “神託” (別途定義) @given(price=prices, coupons=coupons_strategy) @settings(max_examples=200) def test_is_customer_optimal(price: int, coupons: list[Coupon]) -> None: actual = apply_coupons(price, coupons) expected = optimal_model(price, coupons) assert actual == expected, ( f"顧客最適ではない: price={price}, coupons={coupons}, " f"actual={actual}, optimal={expected}" ) REQ3 (顧客最適性) を検証する PBT: 神託パターン
  22. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. def apply_coupons(price: int, coupons: list[Coupon]) -> int: percent_coupons = [c for c in coupons if isinstance(c, PercentOffCoupon)] amount_coupons = [c for c in coupons if isinstance(c, AmountOffCoupon)] total: Decimal = Decimal(price) for c in percent_coupons: total = _apply_one(total, c) for c in amount_coupons: total = _apply_one(total, c) return floor_and_clamp(total) 修正後のクーポン適⽤ロジック PBT で検証済み • REQ2: 切り上げ・切り捨て処理 • REQ3. 顧客最適性 本番環境向け実装: 定率 OFF クーポンを先、 定額 OFF クーポンを後に 適⽤するのが最適
  23. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. プロパティベーステスト Dive Deep
  24. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • “Kiro は⾃然⾔語の仕様を⾃動的に実⾏可能なプロパティに変換し、 包括的なテストケースを⽣成することにより、AIエージェントと ⼈間の開発者の両⽅がより信頼性の⾼いソフトウェアを構築できる 強⼒なフィードバックループを作り出します。” • Kiro IDE の Spec mode (仕様駆動開発) を実⾏すると、 受け⼊れ基準を PBT に変換したテストコードを記述する 1: Kiro IDE と PBT Correctness with Property-based tests: https://kiro.dev/docs/specs/correctness/ より翻訳
  25. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. PBT は⾔語ごとのフレームワーク を⽤いて実⾏する (Python: Hypothesis, Erlang: PropEr, etc.) 1. 多数の⼊⼒値を⽣成する 2. 各⼊⼒値に対してプロパティが成⽴することを検証 3. 「収縮」(Shrinking): • 失敗するテストケースが⾒つかった場合、最⼩の反例を探索する • より単純、⼩さな値の反例やエッジケースを⾒つけることでデバッグが容易に 2: Property-based testing の動作の仕組み ジェネレーター ⼊⼒値 プログラムの正しさを検証 or 反例を発⾒
  26. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 3: EBT と PBT の⽐較 Example-based testing (EBT, 事例ベーステスト) • プログラムへの⼊⼒と期待される出⼒値の組 を記述 • Pros • 予⾒できる・既知のバグを特定できる • 代表例や仕様を明⽰できる • Cons • 予⾒できない・未知のバグへの対応が 難しい Property-based testing (PBT, プロパティベーステスト) • 「どのような⼊⼒値でも常に成⽴する振る舞い」 を記述 • Pros • 未知の⼊⼒に対するバグを特定できる • 少ない記述でより広い問題空間 (⼊出⼒の組合せ) を探索できる • Cons • 振る舞いを適切に抽象化したルールとして 記述することが難しい • → Coding Agent の⽀援で対処可能に
  27. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • PBT は単独でバグが存在しないことを保証するものではない • 定義したプロパティが弱すぎる • ⼊⼒の値の⽣成が⼊⼒としてあり得る範囲をカバーできていない • etc… • PBT で発⾒した反例を EBT に追加することで将来のデグレを予防できる 4: PBT の限界と EBT との補完関係 class TestCouponEBT: def test_定額OFFからのパーセントOFF(self) -> None: coupons = [ AmountOffCoupon(Decimal(1)), PercentOffCoupon(Decimal("0.01")), ] assert apply_coupons(72101, coupons) == 71378 PBT で発⾒した反例
  28. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • 実装もテストも AI が書くと︖ (再掲) まとめ Coding Agent テスト対象 テストコード 要求仕様 これこれを 実装して できました︕ テストもしてます︕ (テストケース数だけは 多いけどこのテストほんまに 信頼できるんかな・・・)
  29. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • 要求仕様・プロパティ& PBT を組み合わせてプログラムの正しさを検証 • Kiro の Spec mode で PBT を試してみよう まとめ Coding Agent 要求仕様 これこれを 実装して できました︕ テストもしてます︕ 確かに仕様とテストが 対応していて 検証されてそうやね テスト対象 テストコード PBT プロパティ
  30. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Coding Agent の ” あなたがコードを記述し、テストを記述するという場合、 その双⽅に誤った仮定が紛れ込んでしまわないのでしょうか︖” ”あなたの抱く予想を共有していないコンピューターが、あなたのために テストを実施するという代替が適切だと考えています” Coding Agent のために Hiroki Yamazaki, 2026 Coding Agent が
  31. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 実践プロパティベーステスト PropErとErlang/Elixirではじめよう 参考⽂献 達⼈プログラマー(第2版) 熟達に向けたあなたの旅
  32. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • 要求仕様・プロパティ& PBT を組み合わせてプログラムの正しさを検証 • Kiro の Spec mode で PBT を試してみよう まとめ Coding Agent 要求仕様 これこれを 実装して できました︕ テストもしてます︕ 確かに仕様とテストが 対応していて 検証されてそうやね テスト対象 テストコード PBT プロパティ
  33. © 2026, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Thank you! ⼭崎 宏紀 (Hiroki Yamazaki) X: https://x.com/yh1roki Linkedin: https://www.linkedin.com/in/hiroki-yamazaki/