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

もう一度テストパターンを整理しよう(WebApp編)

 もう一度テストパターンを整理しよう(WebApp編)

主にモック関連で話をしました。
ここで使った最強のツールはこれです。
https://github.com/Code-Hex/funcy-mock
読みは「ファンキーモック」

See also: https://codehex.hateblo.jp/entry/2018/07/03/211839

Kei Kamikawa

July 03, 2018
Tweet

More Decks by Kei Kamikawa

Other Decks in Programming

Transcript

  1. ΋͏Ұ౓

    ςετύλʔϯΛ੔ཧ͠Α͏
    !NFSDBSJHP
    DPEFIFY

    View full-size slide

  2. who.About(me)

    View full-size slide

  3. !DPEFIFY !$PEF)FY
    w .FSDBSJ *OD
    w *MJLF1FSM94(P
    w )JQIPQ&OHJOFFS/FX
    w IUUQTDPEFIFYIBUFCMPKQ

    View full-size slide

  4. ੔ཧ͗ͨ݁͢͠Ռ

    View full-size slide

  5. ෼Ͱ͸ऩ·Βͳ͔ͬͨͰ͢

    View full-size slide

  6. ओޠ͕Ͱ͔͗͢·ͨ͠͝ΊΜͳ͍͞
    ෼Ͱ͸ऩ·Βͳ͔ͬͨͰ͢

    View full-size slide

  7. ΋͏Ұ౓

    ςετύλʔϯΛ੔ཧ͠Α͏
    !NFSDBSJHP
    DPEFIFY
    8FC"QQฤ ϞοΫ͕ओ

    View full-size slide

  8. ࠓ೔࿩͢಺༰

    View full-size slide

  9. ࠓ೔࿩͢಺༰ʢ݉Ͷͯʣ
    w (Pʹ͓͚Δςετ࣮૷ύλʔϯ
    w ςετΛָ͢ΔͨΊͷઃܭ
    w JOUFSGBDFʹΑΔNPDL࣮૷

    View full-size slide

  10. %#पΓʹ͍ͭͯ
    EBUBCBTFTRM

    View full-size slide

  11. 4FSWJDFͷߏ଄ମͷதʹ

    TRM%#Λ࣋ͨͤͯΔํ͍·ͤΜ͔ʁ

    View full-size slide

  12. ΋ͪΖΜͰ͕͢ɺ

    ͦΕͰ͸%#ؔ࿈ͷςετ͕

    ೉͘͠ͳΓ·͢

    View full-size slide

  13. ͲΜͳJOUFSGBDFΛ

    ࣋ͨͤΔͱ͍͍Ͱ͠ΐ͏͔ʁ

    View full-size slide

  14. ͜ΕΒΛ࣋ͬͨ

    JOUFSGBDF͕ཧ૝తͰ͢

    View full-size slide

  15. ͋ͱ͸ඞཁʹԠͯ͡

    ࣍ͷΑ͏ͳJOUFSGBDFΛ࡞੒

    View full-size slide

  16. ˞ඞཁʹԠͯ͡&YFDFSͳͲΛ֎͠·͠ΐ͏

    View full-size slide

  17. JOUFSGBDFΛҾ਺ʹ࣋ͬͨ
    ؔ਺ͷ࡞੒

    View full-size slide

  18. ˞2VFSZ
    ͚ͩͳΒҾ਺͸

    2VFSZFSΛ౉͢͜ͱ΋ݕ౼Ͱ͖·͢

    View full-size slide

  19. 4FSWJDFߏ଄ମͷϨγʔό͔Β

    ݺͼग़࣌͢ͷ࣮૷

    View full-size slide

  20. ˞/PO5SBOTBDUJPODBTF

    View full-size slide

  21. ͓ͬͱɺ

    5SBOTBDUJPO$BTF͸ʁ

    View full-size slide

  22. τϥϯβΫγϣϯ͕Ͱ͖Δͱ

    ൑அͰ͖ΔΑ͏ͳ

    JOUFSGBDFΛఆٛͯ͋͛͠Δ

    View full-size slide

  23. 5SBOTBDUJPOΛߦ͏ͨΊͷJOUFSGBDF

    View full-size slide

  24. #FHJOOFSΛؚΊͨJOUFSGBDF

    View full-size slide

  25. ECϑΟʔϧυΛ3VOOFSJOUFSGBDF΁

    View full-size slide

  26. 5SBOTBDUJPODBTF

    View full-size slide

  27. %#ͷςετΛ͢ΔͨΊʹ

    ϞοΫΛ࡞੒͠·͢

    View full-size slide

  28. ͜͜·Ͱ࣮ߦ෦෼2VFSZ
    ͷΈ࢖ͬͯΔͨΊमਖ਼

    View full-size slide

  29. ݱࡏͷ3VOOFSJOUFSGBDF͸࣮࣭͜Εͱಉ͡

    View full-size slide

  30. ͜ΕΒͷϝιουΛ࣋ͭߏ଄ମΛ༻ҙͯ͋͛͠Δ
    ˞ಈతʹSFUVSO͢Δ஋ΛมߋͰ͖Δػߏ΋࡞Γ·͠ΐ͏

    View full-size slide

  31. ͜ΕͰϞοΫ͕Ͱ͖ͨ

    View full-size slide

  32. ͱࢥ͍·͔ͨ͠ʁ

    View full-size slide

  33. ͜͏͍͏TRM5YΛѻ͏έʔεͰςετ͕Ͱ͖·ͤΜʂ

    View full-size slide

  34. ԿނͳΒTRM5Y͕ϞοΫԽ
    Ͱ͖ͳ͍͔Β

    View full-size slide

  35. TRM5YΛϞοΫʹͰ͖ΔΑ
    ͏ʹमਖ਼͠·͠ΐ͏ʂ

    View full-size slide

  36. ·ͣ͸5YJOUFSGBDFΛ࡞੒

    View full-size slide

  37. #FHJOOFSJOUFSGBDFΛ
    5YJOUFSGBDFΛฦ͢Α͏ʹमਖ਼

    View full-size slide

  38. 5YJOUFSGBDFΛຬͨ͢ߏ଄ମΛఆٛ

    View full-size slide

  39. ͜͏͍͏͔Μ͡ͰίʔυΛॻ͚͹
    %#पΓͰ΋.PDLΛ࢖ͬͨςετ͕ՄೳͰ͢

    View full-size slide

  40. w TRM%#Λߏ଄ମͷதͰ࣋ͭͷ͸͍͍͕ɺ

    جຊతʹؔ਺ͷҾ਺ʹ౉͢Α͏ʹઃܭ͢Δ
    w ͦͷؔ਺Λϝιουͱͯ͠ϥοϓͯ͋͛͠Δͱྑ͍
    w τϥϯβΫγϣϯΛؚΊΔ৔߹ɺ

    #FHJO
    ϝιουͷฦΓ஋͸TRM5YΛຬͨ͢

    JOUFSGBDFΛࢦఆͯ͋͛͠Δ
    w ͋ͱ͔Β঺հ͢ΔϞοΫٕ๏Ͱ΋ͬͱྑ͍ײ͡ʹͳ
    Γ·͢

    View full-size slide

  41. 4FSWJDFͷ'VODUJPOBMUFTU
    ͱॊೈʹૢ࡞ՄೳͳϞοΫΛ࡞Δ

    View full-size slide

  42. w 6OJUUFTUʢ୯ମςετʣ
    w ୯Ұͷؔ਺΍ϝιουͳͲΛςετ
    w 'VODUJPOBMUFTUʢػೳςετʣ
    w ϦΫΤετ͔ΒϨεϙϯε·Ͱͷςετ

    View full-size slide

  43. w 6OJUUFTUʢ୯ମςετʣ
    w ୯Ұͷؔ਺΍ϝιουͳͲΛςετ
    w 'VODUJPOBMUFTUʢػೳςετʣ
    w ϦΫΤετ͔ΒϨεϙϯε·Ͱͷςετ

    View full-size slide

  44. Ͳ͏͍͏ײ͡Ͱ

    ΍ͬͯΔ͔ͱ͍͏ͱ

    View full-size slide

  45. ςετΛߦ͍͍֤ͨΤϯυϙΠϯτͷొ࿥

    View full-size slide

  46. ςετͷͨΊͷ൚༻ߏ଄ମΛฦ͢

    View full-size slide

  47. • TestGet ΍ TestEcho ͳͲͷ୯ମςετͱ

    ࠞ߹ͤ͞ͳ͍ͨΊʹҰՕॴʹ·ͱΊͯॻ͘
    • funcsεϥΠεʹfunc(*testing.T)Λ࣋ͨͤΔ
    • for rangeͰ̍ͭͣͭ

    ΤϯυϙΠϯτͷ'VODUJPOBMUFTUΛߦ͍ͬͯ͘
    w ֤ΤϯυϙΠϯτςετͷલޙʹॲཧΛ૸ΒͤΔ͜
    ͱ͕Մೳʢ4FUVQ5FBSEPXOʣ

    View full-size slide

  48. ͦͯ͠testGet(u)ͩͱ

    View full-size slide

  49. w ΤϯυϙΠϯτ͝ͱͰඞཁʹԠͯ͡

    ϞοΫΛ࢓ࠐΜͩαʔόʔͷίϯετϥΫτΛߦ͏
    w ΤϯυϙΠϯτ͝ͱͰେ·͔ͳϞοΫͷॲཧΛม
    ߋͰ͖Δ
    w ςετॱΛγϟοϑϧͰ͖Δ
    w ֤ςετͷલޙʹॲཧΛ૸ΒͤΔ͜ͱ͕Մೳ

    ʢ4FUVQ5FBSEPXOʣ

    View full-size slide

  50. ࣮ࡍʹϞοΫΛ࡞੒͢Δ෦෼

    View full-size slide

  51. ςετΛॻ͖͍ͨ΋ͷΛ

    ໭ͬͯ֬ೝ͠·͢

    View full-size slide

  52. testGetWithFailedAuth Λ

    ࡞੒͠·͢

    View full-size slide

  53. ೝূͰࣦഊ͍ͤͨ͞ͷͰ

    "VUI4FSWJDFͷϞοΫ͔Β

    View full-size slide

  54. ͜ͷϞοΫΛ࢖ͬͨ

    testGetWithFailedAuth

    View full-size slide

  55. w Ұ࣌ม਺ʹϞοΫΛॳظԽͨ͠΋ͷʢϙΠϯλʣΛ
    ౉ͯͦ͠ΕΛ4FSWFSߏ଄ମͷϑΟʔϧυʹ࣋ͨͤ
    Δ
    w ͜͏͢Δͱม਺ܦ༝ͰϞοΫͷத਎ΛมߋͰ͖Δͷ
    Ͱؾָ

    View full-size slide

  56. ͜ͷϞοΫٕ๏࠷ڧ

    View full-size slide

  57. ࢥ͍͍ͭͨΦϨշௐ
    ʢ࣮͸ͪΌΜͱӆΛ౿ΜͰ͍·͢ʣ

    View full-size slide

  58. ͳͷͰ4FFBMTP
    IUUQIBZBCVTBDPNHPMBOHIPXUPXSJUFNPDLPGJOUFSGBDFGPSUFTUJOH

    View full-size slide

  59. 6TFS4FSWJDFͷ৔߹ͳͲ

    View full-size slide

  60. JOUFSGBDFʹൺྫͯ͠

    ୔ࢁॻ͔ͳ͚Ε͹͍͚ͳ͍

    View full-size slide

  61. ͦ͜Ͱ͜ͷπʔϧ
    IUUQTHJUIVCDPN$PEF)FYGVODZNPDL
    $ funcygen interface.go

    View full-size slide

  62. Կճ΋ॻ͘ͷ͸໘౗ͳͷͰ

    ָͰ͖ΔՕॴ͸ָ͠·͠ΐ͏

    View full-size slide

  63. ·ͱΊ
    w ઃܭஈ֊ͰͲ͏ϞοΫΛૠೖ͠΍͘͢͢Δ͔

    ૝ఆͯ͠ઃܭ͢ΔͱΈΜͳ޾ͤ
    w ࠓճ͸%#ͱΞϓϦέʔγϣϯͷϞοΫʹؔͯ͠
    ॻ͖·ͨ͠
    w ָͰ͖Δͱ͜Ζ͸ָ͍ͨ͠

    View full-size slide