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

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

D7b086b9c6bb828f15cd7a9ff9b8c688?s=128

Shintani Teppei

June 08, 2020
Tweet

Transcript

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

    @euglena1215 ద੾ͳྔͷςετΛॻͨ͘Ίʹࣗ෼͕ؾΛ͚͍ͭͯΔ͜ͱ ࣾһݚम 2020
  2. ©2020 Wantedly, Inc. 5FQQFJ4IJOUBOJ !FVHMFOB w "VUI4RVBE1SFNJVN4RVBE w ৽ଔ೥໨ w

    3VCZ͕޷͖ ࣗݾ঺հ
  3. ©2020 Wantedly, Inc. ద੾ͳྔͷςετ

  4. ©2020 Wantedly, Inc. ࠓ೔ͷΰʔϧ 1VMM3FRVFTUΛ࡞ͬͨͱ͖ʹ ద੾ͳྔͷςετΛॻ͚͍ͯΔ͔ ڳʹखΛ౰ͯͯߟ͑Δ͜ͱ͕Ͱ͖Δ ࣗ෼͕ߟ͍͑ͯΔ͜ͱΛݴޠԽͯ͠ΈͨͷͰ঺հ͠·͢

  5. ©2020 Wantedly, Inc. ࿩͢͜ͱ࿩͞ͳ͍͜ͱ w ࿩͢͜ͱ • ͲΜͳͱ͖ʹςετΛॻ͘ඞཁੑ͕ߴ͍ͷ͔ • ͲΜͳͱ͖ʹςετΛॻ͘ඞཁੑ͕௿͍ͷ͔

    w ࿩͞ͳ͍͜ͱ • ମܥతͳςετख๏΍ςετͷ෼ྨ → ࣗ෼͕͋·Γ஌Βͳ͍ʢ@qnighy ͕ৄͦ͠͏(͠ΒΜ͚Ͳ)ʣ • TDDͳͲͷಛఆͷϓϩάϥϜ։ൃख๏ → ࣗ෼͕͋·Γ஌Βͳ͍ʢ@stomk ͕ৄͦ͠͏(͠ΒΜ͚Ͳ)ʣ
  6. ©2020 Wantedly, Inc. ߦͰ·ͱΊΔͱ ςετίʔυͷඞཁੑ มߋස౓ʷ։ൃਓ਺ʷॏཁ౓

  7. ©2020 Wantedly, Inc. ςετίʔυͷඞཁੑมߋස౓º։ൃਓ਺ºॏཁ౓ 1. 1೔ʹ1౓มߋ͞ΕΔՕॴͳͷ͔ɺ1೥ʹ1౓มߋ͞ΕΔՕॴͳͷ͔ 2. มߋස౓͕௿͚Ε͹खಈςετͷํ͕ίεύྑ͍Մೳੑ΋͋Δ 1. ࣗಈςετ

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

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

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

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

    ࣮૷ऀҎ֎͕ςετॻ͘ͱ͖ͷSTEP 1. ͲΜͳςετέʔε͕ଘࡏ͢Δͷ͔೺Ѳ͢Δ ←͕͜͜লུͰ͖Δ͚ͩͰ΋͔ͳΓخ͍͠ 2. ςετΛॻ͘
  12. ©2020 Wantedly, Inc. ߦͰ·ͱΊΔͱ ςετίʔυͷඞཁੑ มߋස౓ʷ։ൃਓ਺ʷॏཁ౓

  13. ©2020 Wantedly, Inc. ࠓ೔ͷΰʔϧ 1VMM3FRVFTUΛ࡞ͬͨͱ͖ʹ ద੾ͳྔͷςετΛॻ͚͍ͯΔ͔ ڳʹखΛ౰ͯͯߟ͑Δ͜ͱ͕Ͱ͖Δ