$30 off During Our Annual Pro Sale. View Details »

どんなときにテストを書いた方がいいのか/When should you write a test?

どんなときにテストを書いた方がいいのか/When should you write a test?

Shintani Teppei

June 08, 2020
Tweet

More Decks by Shintani Teppei

Other Decks in Programming

Transcript

  1. ©2020 Wantedly, Inc. ͲΜͳͱ͖ʹςετΛॻ͍ͨํ͕͍͍ͷ͔ Jun 3, 2020 - Teppei Shintani

    @euglena1215 ద੾ͳྔͷςετΛॻͨ͘Ίʹࣗ෼͕ؾΛ͚͍ͭͯΔ͜ͱ ࣾһݚम 2020
  2. ©2020 Wantedly, Inc. ࿩͢͜ͱ࿩͞ͳ͍͜ͱ w ࿩͢͜ͱ • ͲΜͳͱ͖ʹςετΛॻ͘ඞཁੑ͕ߴ͍ͷ͔ • ͲΜͳͱ͖ʹςετΛॻ͘ඞཁੑ͕௿͍ͷ͔

    w ࿩͞ͳ͍͜ͱ • ମܥతͳςετख๏΍ςετͷ෼ྨ → ࣗ෼͕͋·Γ஌Βͳ͍ʢ@qnighy ͕ৄͦ͠͏(͠ΒΜ͚Ͳ)ʣ • TDDͳͲͷಛఆͷϓϩάϥϜ։ൃख๏ → ࣗ෼͕͋·Γ஌Βͳ͍ʢ@stomk ͕ৄͦ͠͏(͠ΒΜ͚Ͳ)ʣ
  3. ©2020 Wantedly, Inc. ςετίʔυͷඞཁੑมߋස౓º։ൃਓ਺ºॏཁ౓ 1. 1೔ʹ1౓มߋ͞ΕΔՕॴͳͷ͔ɺ1೥ʹ1౓มߋ͞ΕΔՕॴͳͷ͔ 2. มߋස౓͕௿͚Ε͹खಈςετͷํ͕ίεύྑ͍Մೳੑ΋͋Δ 1. ࣗಈςετ

    ϥϯχϯάίετ ௿ / Πχγϟϧίετ ߴ 2. खಈςετ ϥϯχϯάίετ ߴ / Πχγϟϧίετ ௿ w FY JOJUJBMJ[FS CBUDIpMF มߋස౓͕ߴ͚Ε͹ߴ͍΄Ͳ ςετίʔυͷඞཁੑ΋ߴ·Δ
  4. ©2020 Wantedly, Inc. ςετίʔυͷඞཁੑมߋස౓º։ൃਓ਺ºॏཁ౓ 1. ͦͷϑΝΠϧΛมߋ͢Δਓ਺Ͱ͸ͳͯ͘ɺͦͷมߋӨڹΛड͚Δ։ൃऀͷਓ਺ 1. app/models/user.rb Λมߋͨ͠Βbackend։ൃͯ͠Δ΄΅શһ͕ӨڹΛड͚ΔՄೳੑ͕ ߴ͍

    2. view ΑΓ΋ controller, controller ΑΓ΋ model ͷํ͕ӨڹΛड͚Δ։ൃऀͷਓ਺͸ଟ͘ͳ Γ͕ͪ 3. ։ൃਓ਺͕1,2ਓͰ͋Ε͹͋Δఔ౓ѨჴͷݺٵͰ͍͚ͨΓ͢Δ 1. ʮ͜͜Λมߋ͢Δͬͯ͜ͱ͸͋ͬͪ΋ಉ࣌ʹมߋ͠ͳ͍ͱ͜ͷέʔεͰյΕΔͷͰ͸ʁʯ 2. ։ൃਓ਺͕ଟ͘ͳͬͯ͘ΔͱѨჴͷݺٵ͸͔ͳΓࠔ೉ 3. ਺Χ݄ޙͷࣗ෼͸ผਓͰ͋Δ͜ͱʹ஫ҙ
  5. ©2020 Wantedly, Inc. ςετίʔυͷඞཁੑมߋස౓º։ൃਓ਺ºॏཁ౓ 1. ͕ͦ͜յΕͨΒͲͷ͘Β͍ࠔΔ͔ 1. Α͋͘ΔࢦඪɿӨڹϢʔβʔ਺ɺച্ 1. ࢀߟɿฏ೔ͷ೔தʹ1࣌ؒαʔϏε͕μ΢ϯ͢ΔͱXXXXສԁఔ౓ͷଛࣦ

    ͜͜ʹ issue URL ͕ೖΔ 2. ͜ΕΒΛ͋Δఔ౓Χόʔ͍ͯ͠Δͷ͕ SLI/SLO ର৅ endpoint Ұཡ ͜͜ʹ issue URL ͕ೖΔ 1. ͜ͷ endpoint ͕յΕΔՄೳੑͷ͋Δมߋ͸ॏཁ౓͕ߴ͍ͱࢥͬͯࠩ͠ࢧ͑ͳͦ͞͏
  6. ©2020 Wantedly, Inc. ςετΛॻ͔ͳ͍͍ͯ͘έʔε͸ʜʁ  ྫ͑͹ϋοΧιϯ  มߋස౓ˠϋοΧιϯऴΘͬͨΒϙΠࣺͯͳͷͰ ΄΅ 

    ։ൃਓ਺ˠdਓ͘Β͍ʁѨჴͷݺٵͰ௨͡Δ  ॏཁ౓ˠൃදͰόάΒͳ͚Ε͹0,ɺച্ͳ͍ͷ Ͱۚમμϝʔδ΋
  7. ©2020 Wantedly, Inc. ͏Δͤ͑ɺͪ͜ͱΒϦϦʔεલͳΜ͡Όʂ  ࠷খݶͷਖ਼ৗܥͷΈςετॻ͘  ࢒Γ͸ςετέʔε͚ͩॻ͍ͯ AQFOEJOHlޙ͸೚ͤͨA 1.

    ࣮૷ऀҎ֎͕ςετॻ͘ͱ͖ͷSTEP 1. ͲΜͳςετέʔε͕ଘࡏ͢Δͷ͔೺Ѳ͢Δ ←͕͜͜লུͰ͖Δ͚ͩͰ΋͔ͳΓخ͍͠ 2. ςετΛॻ͘