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

APIシナリオテストツールとしてのrunn / 4 API testing tools

APIシナリオテストツールとしてのrunn / 4 API testing tools

APIテストツール4選!開発者が語る各ツールの特徴と魅力
https://trident-qa.connpass.com/event/299308/

このセッションではAPIシナリオテストツールとしてrunnで何ができるのかを紹介します。 また、runnの開発者として「runnがどのような設計思想で開発されているのか」「runnはどのようなAPIテストに向いていてどのようなAPIテストに向いていないのか」など直球で紹介できればと思います。

Ken’ichiro Oyama

November 30, 2023
Tweet

More Decks by Ken’ichiro Oyama

Other Decks in Technology

Transcript

  1. APIγφϦΦςετπʔϧͱͯ͠ͷ
    runn
    খࢁ݈Ұ࿠ / GMO PEPABO inc.
    2023.11.30 APIςετπʔϧ̐બʂ։ൃऀ͕ޠΔ֤πʔϧͷಛ௃ͱັྗ
    1

    View full-size slide

  2. ࣗݾ঺հ
    ٕज़෦ɹٕज़ج൫νʔϜ
    2018೥ த్ೖࣾ
    খࢁ ݈Ұ࿠ Ken’ichiro Oyama
    গ࣮͠༻తͰখ͞ͳOSSΛॻ͘ͷ͕झຯɻ
    ● GitHub : k1LoW
    ● Twitter : @k1LoW
    2

    View full-size slide

  3. GMOϖύϘʹ͍ͭͯ
    3
    https://pepabo.com

    View full-size slide

  4. • runn ( means "Run N". is pronounced /rʌ́n én/. ) is a package/tool for running operations
    following a scenario.
    • https://github.com/k1LoW/runn
    • γφϦΦΛYAMLͰॻ͍ͯͦΕΛ΋ͱʹૢ࡞ʢΦϖϨʔγϣϯʣΛࣗಈԽͰ͖Δύο
    έʔδ/πʔϧ
    • ίϚϯυͱͯ͠΋GoͷύοέʔδʢϥΠϒϥϦʣͱͯ͠΋࢖͑Δ
    • APIςετ΋ϢʔεέʔεͷϑΝʔετϓϥΠΦϦςΟͱͯ͠Ґஔ෇͚͍ͯΔ
    5
    https://github.com/k1LoW/runn
    runnʢϥϯΤψʣ

    View full-size slide

  5. 6
    https://github.com/k1LoW/runn
    runnʹ͓͚ΔAPIςετͷ࣮ߦ
    > runn run **/*.yml

    View full-size slide

  6. 7
    γφϦΦYAMLϑΝΠϧ
    ʢϥϯϒοΫʣ

    View full-size slide

  7. 8
    https://github.com/k1LoW/runn

    View full-size slide

  8. 9
    https://github.com/k1LoW/runn

    View full-size slide

  9. 10
    https://github.com/k1LoW/runn

    View full-size slide

  10. 11
    https://github.com/k1LoW/runn

    View full-size slide

  11. 12
    https://github.com/k1LoW/runn

    View full-size slide

  12. 13
    https://github.com/k1LoW/runn

    View full-size slide

  13. 14
    https://github.com/k1LoW/runn

    View full-size slide

  14. 15
    https://github.com/k1LoW/runn
    Runnerͷઃఆ
    ม਺ͷઃఆ
    ɹɹɹɹ֤εςοϓ
    0
    1
    2
    3

    View full-size slide

  15. 16
    runnͷػೳ

    View full-size slide

  16. • 1όΠφϦͷγφϦΦ࣮ߦͷCLIίϚϯυʢπʔϧʣͱͯ͠࢖༻Ͱ͖Δ
    • 1όΠφϦ = CIϑϨϯυϦ
    • ͞·͟·ͳϓϩτίϧʹରԠ͓ͯ͠Γɺ1ͭͷγφϦΦ಺Ͱෳ਺૊Έ߹ΘͤΔ͜ͱ͕Մೳ
    • HTTP
    • gRPC
    • DatabaseʢSQLʣ
    • Chrome DevTools Protocol
    • ೚ҙίϚϯυͷ࣮ߦʢϩʔΧϧ/SSHʣ
    • GoͷTest Helperʢύοέʔδʣͱͯ͠࢖༻Ͱ͖Δ
    17
    https://github.com/k1LoW/runn
    runnͷػೳʢv0.91.0ʣʢ1/2ʣ

    View full-size slide

  17. 18
    https://github.com/k1LoW/runn
    runnͷػೳʢv0.91.0ʣʢ2/2ʣ
    • γφϦΦϑΝΠϧʢYAMLʣͷϑΥʔϚοτ͕OpenAPI SpecϥΠΫ
    • γφϦΦ಺ͷεςοϓؒͷ஋͕ࣗಈͰ࿈ܞ͞Ε͍ͯΔ
    • ʮεςοϓAΛ࣮ߦ͔ͯ͠Βͦͷ݁ՌΛ࢖ͬͯεςοϓBΛ࣮ߦ͢Δʯͱ͍͏γφϦΦΛߏங͠΍͍͢
    • ෳ਺ͷγφϦΦͷ࣮ߦΛ૝ఆ࣮ͨ͠૷
    • ෳ਺ͷγφϦΦͷ෼ׂ࣮ߦɺαϯϓϦϯά࣮ߦɺϥϯμϜ࣮ߦͳͲ͕Մೳ
    • ϧʔϓ࣮ߦ΍ϦτϥΠ࣮ߦͷ࢓૊Έ͕૊ΈࠐΈͰඋΘ͍ͬͯΔ
    • ಉ͡γφϦΦϑΝΠϧΛ࢖ͬͨෛՙςετʢϩʔυςετʣ͕Մೳ
    • ίϚϯυΛ runn run ͔Β runn loadt ʹมߋ͢Δ͚ͩɻෳ਺γφϦΦ࣮ߦ΋ͦͷ··Մೳ
    • γφϦΦ࣮ߦͷϩά΋ه࿥Մೳ
    • γφϦΦ࣮ߦͷϓϩϑΝΠϧ΋औಘՄೳʢ֤εςοϓͷܦա࣌ؒʣ

    View full-size slide

  18. 19
    runn͸
    ͲͷΑ͏ͳઃܭࢥ૝Ͱ
    ࡞ΒΕ͍ͯΔͷ͔

    View full-size slide

  19. • ϝΠϯͰ։ൃ͍ͯ͠Δͷ͸ @k1LoW ɹɹɹͱ @k2tzumi ɹɹɹ ͷ2ਓ
    • ͦΕͧΕrunnΛυοΫϑʔσΟϯά͍ͯͯ͠ɺ@k1LoW͕Goύοέʔδͱͯ͠ͷ
    runnɺ@k2tzumi͕ίϚϯυͱͯ͠ͷrunnΛओʹ࢖͍ͬͯΔ
    • υοΫϑʔσΟϯάΛ͍ͯ͠ΔதͰඞཁͱײͨ͡΋ͷ͕࣮૷͞ΕΔ͜ͱ͕ଟ͍
    • GitHubͷIssue/Pull Request΍X(Twitter)ͷϋογϡλά #runn։ൃऀձٞ Λத৺ʹ
    ํ਑΍։ൃΛਐΊΔʢ࣌ʑϦϞʔτɺ࣌ʑΧϯϑΝϨϯεͷ࿓Լʣ
    20
    runn͸ͲͷΑ͏ͳઃܭࢥ૝Ͱ࡞ΒΕ͍ͯΔͷ͔
    runnͷ։ൃମ੍

    View full-size slide

  20. γφϦΦͷॻ͖৺஍͕ྑ͍͜ͱ
    21

    View full-size slide

  21. • ૝ఆ͍ͯ͠ΔϝΠϯͷϢʔβ͸ʮAPIΛ։ൃ͍ͯ͠ΔΤϯδχΞʯ
    • OpenAPI SpecϥΠΫͳϑΥʔϚοτΛ࠾༻ͨ͠ͷ΋ɺγφϦΦςετΛॻ͘
    ΤϯδχΞͱOpenAPIυΩϡϝϯτΛॻ͘ΤϯδχΞΛಉҰਓ෺ͱͯ͠ߟ͑ͯ
    ͍ͨͨΊ
    • ॻ͖׳Ε͍ͯΔϢʔβ͕Ͱ͖Δ͚ͩ௚ײతʹॻ͚ΔΑ͏ʹɻͦΕ͕γφϦΦΛॻ͘
    ίετΛԼ͛Δͱ৴͍ͯ͡Δ
    • ෳ਺ͷγϯλοΫεͷαϙʔτΛ͢Δ͜ͱͰॻ͖΍͘͢
    • εςοϓؒͷ҉໧ͷ஋ͷड͚౉͠Λ͢Δ͜ͱͰඞཁҎ্ʹॻ͘͜ͱΛݮΒ͢
    22
    runn͸ͲͷΑ͏ͳઃܭࢥ૝Ͱ࡞ΒΕ͍ͯΔͷ͔
    γφϦΦͷॻ͖৺஍͕ྑ͍͜ͱ

    View full-size slide

  22. 23
    runn͸ͲͷΑ͏ͳઃܭࢥ૝Ͱ࡞ΒΕ͍ͯΔͷ͔
    ෳ਺ͷγϯλοΫεͷαϙʔτʢsteps:ͷListͱMapʣ
    • steps: ηΫγϣϯͷॻ͖ํʹListํࣜͱMapํࣜͷ2ͭΛ༻ҙ

    View full-size slide

  23. 24
    runn͸ͲͷΑ͏ͳઃܭࢥ૝Ͱ࡞ΒΕ͍ͯΔͷ͔
    ෳ਺ͷγϯλοΫεͷαϙʔτʢγϯλοΫεγϡΨʔʣ
    • γϯλοΫεγϡΨʔΛ༻ҙɻৄࡉΛॻ͖͍ͨͱ͖͚ͩৄࡉΛॻ͚ΔΑ͏ʹ

    View full-size slide

  24. 25
    runn͸ͲͷΑ͏ͳઃܭࢥ૝Ͱ࡞ΒΕ͍ͯΔͷ͔
    ෳ਺ͷγϯλοΫεͷαϙʔτʢγφϦΦؒͷ஋ͷ࠶ར༻ʣ
    • ֤εςοϓͷϨεϙϯε͸҉໧తʹอ࣋͢Δʢ໌ࣔతʹॻ͘ඞཁ͸ͳ͍ʣ
    • ྫ͑͹࠷ॳͷεςοϓͰ͋ΔAPI΁HTTPϦΫΤετΛͯ࣍͠ͷεςοϓͰϨεϙϯεΛ
    ࢖༻͍ͨ࣌͠
    • ʮલεςοϓͷΠϯσοΫε͸3ʯ͕಄ʹ͋Ε͹ steps[3].res Ͱऔಘ
    • Listه๏
    • ʮલεςοϓͷΩʔ͸fooʯ͕಄ʹ͋Ε͹ steps.foo.res Ͱऔಘ
    • Mapه๏
    • ʮલͷεςοϓʯ͕಄ʹ͋Ε͹ previous.res Ͱऔಘ

    View full-size slide

  25. γϯϓϧʹݟ͑Δ͜ͱ
    26

    View full-size slide

  26. 27
    runn͸ͲͷΑ͏ͳઃܭࢥ૝Ͱ࡞ΒΕ͍ͯΔͷ͔
    ಋೖ͸γϯϓϧʹ
    • 1όΠφϦ
    • ؆୯Πϯετʔϧʢ brew install k1LoW/tap/runn ʣ
    • θϩίϯϑΟάͰςετ࣮ߦʢ runn run **/*.yml ʣ
    • cURL΍ΞΫηεϩά͔ΒͷγφϦΦϑΝΠϧͷੜ੒ʢ runn new ʣ
    • ͳΜͳΒϦϞʔτͷγφϦΦϑΝΠϧΛ࣮ߦʢ —-scopes run:remote ʣ

    View full-size slide

  27. 28
    runn͸ͲͷΑ͏ͳઃܭࢥ૝Ͱ࡞ΒΕ͍ͯΔͷ͔
    ֮͑Δ͜ͱ͸γϯϓϧɻͨͩɺ֮͑ͨ͜ͱͰͰ͖ͦ͏ͳ͜ͱ͕ʮ࣮͸Ͱ͖ΔʯΑ͏ʹ
    • ࣮͸ɺloop: ηΫγϣϯͰϦτϥΠͷઃఆ͕Ͱ͖Δ
    • ࣮͸ɺSSHϥϯφʔΛ࢖ͬͯϙʔτϑΥϫʔσΟϯά͕Ͱ͖Δ
    • ࣮͸ɺγφϦΦͷ࣮ߦΛγϟοϑϧͨ͠Γ෼ׂͨ͠ΓαϯϓϦϯάͨ͠ΓͰ͖Δ
    • ࣮͸ɺࣦഊͨ͠γφϦΦ͚ͩΛ࠶࣮ߦ͢Δ͜ͱ͕Ͱ͖Δ
    • ࣮͸ɺ࣮ߦ͕࣌ؒେ͖͍γφϦΦΛ༏ઌ࣮ͯ͠ߦ͢Δ͜ͱ͕Ͱ͖Δ
    ৽͍͠ػೳΛ1ͭ࡞Δ࣌ɺͦͷػೳͱطଘͷػೳͷ૊Έ߹Θͤ·ͰؚΊͯσβΠϯ͢Δ

    View full-size slide

  28. 29
    runn͸ͲͷΑ͏ͳઃܭࢥ૝Ͱ࡞ΒΕ͍ͯΔͷ͔
    runnͷઃܭࢥ૝
    • ʢݸਓతʹ͸͡Ίͯઃܭࢥ૝ΛݴޠԽͨ͠ʣ
    • γφϦΦͷॻ͖͕ͪ͜͝ྑ͍͜ͱ
    • runnࣗମ͸GoݴޠͰॻ͔Ε͍ͯΔ͕runnͷγφϦΦϑΝΠϧͷγϯλοΫεʹ
    ͍࣋ͬͯΔΠϝʔδ͸Rubyݴޠ
    • γϯϓϧʹݟ͑Δ͜ͱ
    • Θ͔Γ΍͢͞ΛॏࢹɻϔϏʔϢʔεͷͨΊͷػೳ͸ݟ͑ʹͯ͘͘ྑ͍
    • ͋ͱ͸࣮ࡍʹग़ݱ͖ͯͨ͠χʔζʹ߹Θͤͯ੒௕͍ͤͯ͘͞

    View full-size slide

  29. 30
    runn͸
    ͲͷΑ͏ͳAPIςετʹ޲͍͍ͯͯ
    ͲͷΑ͏ͳAPIςετʹ޲͍͍ͯͳ͍ͷ͔

    View full-size slide

  30. 31
    runn͸ͲͷΑ͏ͳAPIςετʹ޲͍͍ͯͯͲͷΑ͏ͳAPIςετʹ޲͍͍ͯͳ͍ͷ͔
    runn͕޲͍͍ͯΔAPIςετ
    • APIΛ։ൃ͢ΔΤϯδχΞ͕ɺAPIͷ։ൃ։͔࢝࣌Β࣮ࢪ͢ΔAPIςετ
    • cURLʹΑΔख࡞ۀʹΑΔڍಈ֬ೝͷ୅ΘΓʹಋೖ͢Δͷ͕͍͔ܰ΋
    • APIαʔό͕Goͷ৔߹runnΛ૊ΈࠐΉ͜ͱͰ go test Ͱ࣮ߦͰ͖Δ
    • ෳ਺ͷϦΫΤετΛ·͍ͨͩγφϦΦ͕ଟ͋͘ΔAPIςετ
    • εΩʔϚۦಈͷ։ൃݱ৔
    • γϯλοΫε͕ࣅ͍ͯΔͷͰࢀߟʹ͠΍͍͢
    • OpenAPI Spec΍Protocol Buffersʢ.protoϑΝΠϧʣʹΑΔϦΫΤετ/Ϩεϙϯε
    ͷγφϦΦࣗମͷόϦσʔγϣϯ΋Ͱ͖Δ

    View full-size slide

  31. 32
    runn͸ͲͷΑ͏ͳAPIςετʹ޲͍͍ͯͯͲͷΑ͏ͳAPIςετʹ޲͍͍ͯͳ͍ͷ͔
    runn͕޲͍͍ͯͳ͍APIςετ
    • ϦΫΤετ/Ϩεϙϯεͷ1ϖΞ͚ͩͰࡁΉΑ͏ͳAPIςετ͕ଟ͍৔߹
    • ςετʹରͯ͠runnͷγφϦΦϑΝΠϧͷهड़͕ଟগ৑௕͔΋͠Εͳ͍
    • OpenAPI Spec΍Protocol Buffersʢ.protoϑΝΠϧʣʹ׳Ε͍ͯͳ͍։ൃݱ৔
    • runnͷγφϦΦϑΝΠϧͷγϯλοΫε͕ཪ໨ʹͰͦ͏
    • ٯʹrunnͷγϯλοΫεʹͳΕͨΒOpenAPI Spec͕ಡΈ΍͘͢ͳΔੈք…

    View full-size slide

  32. 34
    PR
    • by @k2tzumi
    • https://qiita.com/advent-calendar/2023/runn-
    tutorial
    • ໌೔2023೥12݄1೔͔Β։࢝!!!!
    runn։ൃऀʹΑΔrunnνϡʔτϦΞϧ

    View full-size slide

  33. 35
    PR
    runn։ൃऀʹΑΔrunnΫοΫϒοΫ
    • by @k1LoW
    • https://zenn.dev/k1low/books/runn-cookbook
    • Ұ෦༗ྉͰ͕͢ଟ͘Λແྉެ։͍ͯ͠ΔͷͰ
    ͚ͦͩ͜Ͱ΋Ͱ͖Δ͜ͱ͕ݟ͖͑ͯ·͢

    View full-size slide

  34. 36
    Thank you!!!

    View full-size slide