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

Web-E2E-Testing-from-Ruby

 Web-E2E-Testing-from-Ruby

70e13d9877054026fda46d5a5b53a236?s=128

MOROHASHI Kyosuke

December 05, 2017
Tweet

Transcript

  1. Ruby && Webํ໘͔Βݟ͑ͨ
 ΤϯυπʔΤϯυςετͷ
 ྺ࢙ͱࢥ͍ग़ ॾڮګհ @moro 

  2. ‣ (ࣸਅ) ղফͰ͖ͨෆ҆ 

  3.  Kyosuke MOROHASHI moro moro

  4. None
  5. લ࢙ 

  6. ‣ ΞϓϦέʔγϣϯͷ਽ܗΛ࡞Δͱςετ؀ڥ͕͍ͭͯ͘Δɻ ‣ test/models, test/controllers, test/views … ‣ ʮ୯ମʯςετ͕த৺ Ruby

    on Rails 
  7. ‣ & rspec_rails ‣ spec/models, spec/controllers, …. RSpec 

  8. ‣ ϞσϧɾϏϡʔɾίϯτϩʔϥΛ౷߹(integrate)ͯ͠
 ςετ͢Δɻ ‣ ୯ҰϦΫΤετʹ͓͍ͯɺΞϓϦέʔγϣϯͷ֤ϨΠϠ͕ ҙਤ௨Γ౷߹ͯ͠ಈ͔͘ɺΛςετ͢Δɻ ‣ ෳ਺ϦΫΤετʹΘͨΔڍಈ(͋ͷը໘͔Β͜ͷը໘ʹભҠͯͦ͠ΕΛೖྗ…) ͸ ςετͰ͖ͳ͍ɻ

    Integration test / Request spec 
  9. ‣ ϒϥ΢βૢ࡞ΛࣗಈԽͯ͠ςετ͢Δ Selenium ͱɺ ‣ ਓؒͷૢ࡞Λه࿥ͯ͠ςετέʔεΛ࡞ͬͯ͘ΕΔ Selenium IDE Selenium &

    Selenium IDE 
  10. ‣ ϓϩδΣΫτϝϯόʔ͕ɺຖே࠷৽ͷίʔυΛνΣοΫΞ ΢τͯ͠Ұ௨Γ৮ͬͯΈΔɻԿ͔͋Ε͹͙͢ʹ௚͢ɻ खಈͰͷܧଓతE2Eςετ 

  11. ෳ਺ϦΫΤετʹ·͕ͨΔɺϢʔβʔ͕࣮ࡍʹ࢖͏
 γφϦΦʹԊͬͨςετ͸Αͦ͞͏ɻ ͜ͷ࣌఺Ͱ͸·ͩखಈςετɺ࣮ߦ͢Δͷ͕େมɻ Selenium IDEͰه࿥ͨ͠ςετ͸͙͢յΕΔɻ ࣮ײͰ͖ͨ͜ͱ 

  12. Webrat + Cucumber 

  13. ‣ ΤϯυπʔΤϯυςετΛɺࣗવݴޠͰ͔͚Δɻ ‣ MVCϨΠϠ௨؏ & ෳ਺ΞΫγϣϯ ‣ ࣗવݴޠͰςετ͕͔͚Δɻ ‣ Gherkin

    ϑΥʔϚοτ ‣ Given, When, Then / લఏɺ΋͠ɺͳΒ͹ Cucumber 
  14. ‣ Cucumber ͷόοΫΤϯυɺWebΞϓϦΛςετ͢Δͨ ΊͷϥΠϒϥϦɻ ‣ ηογϣϯ(cookie)ΛҾ͖ͭ͛Δ ‣ ʮෳ਺ϦΫΤετΛॱ൪ʹݺΜͩʯςετ͕͔͚ΔΑ͏ʹ ‣ ϦϯΫ΍ϑΥʔϜΛૢ࡞͢Δ(ͭ΋ΓͰ࢖͑Δ)API͕͋ͬͨ

    Webrat 
  15. ‣ ࣗવݴޠͰॻ͍ͨ *.feature Λಈ͔ͨ͢Ίͷ࢓૊ΈΛ step_definitions ͱͯ͠ॻ͘ɻ ‣ step_definitions ͷத͸Rubyίʔυɻࣗવݴޠͱ͸
 ਖ਼نදݱͰϚονϯά͞ΕΔɻ

    Cucumber + Webrat 
  16. None
  17. ‣ Gherkin ςΩετΛϓϩάϥϚͱɺϓϩάϥϚͰ͸ͳ͍ਓ ͱɺڞ༗Ͱ͖ͳ͍͔ͨΊͨ͠ɻ ‣ ϏδωεαΠυ΁ͷ࢓༷ݕ౼/߹ҙʹ ‣ ݟੵ΋Γ୯Ґʹ࢖ͬͯΈͨΓ΋ ‣ νʔϜͷ৽ϝϯόʔ΁ͷઆ໌ʹ

    ‣ ։ൃ࣌ͷҙࣝ߹Θͤʹ (feature͚ͩॻ͍ͨੜࣽ͑PRΛϨϏϡʔͨ͠Γ) ࢲͱCucumber 
  18. Web ͷɺγφϦΦهड़Ͱ͖ΔE2Eࣗಈςετͷ࢓૊Έ͸ ΍͸Γͪΐ͏΂ΜΓɻ ฼ޠͰॻ͍ͯ͋Δͷ΋ɺ΍ͬͯΈΔͱΘ͔Γ΍͍͢ɻ ૿͑ͨ૚͕ʮ೔ຊޠϓϩάϥϛϯάʯʹͳͬͯ͠·͏ͱ
 ϓϩάϥϚʹͱͬͯ͸൥ࡶͳ͚ͩɻ ࣮ײͰ͖ͨ͜ͱ 

  19. “ ࣮ࡍʹ͸ɺͦΕΒ͸ඇٕज़ܥͷεςʔΫϗϧμʔ
 ʢར֐ؔ܎ऀʣͱҰॹʹςετΛॻ͘ͱ͍͏ɺ
 Սۭͷ৔ॴͰ͔͠໾ʹཱͪ·ͤΜɻ https://martinfowler.com/bliki/DynamicTyping.html 
 ( http://bliki-ja.github.io/DynamicTyping/ )

  20. 

  21. ‣ ඞͣ͠΋ʮॻ͍ͯʯ΋ΒΘͳ͚Ε͹ͳΒͳ͍Θ͚Ͱ͸ͳ͍ɻ ‣ ಉ͡දݱͰεςʔΫϗϧμʔ͕Έͳڞ௨ཧղ͢Δͷ͕େࣄɻ ‣ ʮεςʔΫϗϧμʔʯʹ͸΋ͪΖΜɺ։ൃνʔϜ΋ؚ·ΕΔɻ ‣ ͦͷͨΊͷݴޠ΍ޠኮΛҭͯΔͷ͕େ੾ͩͬͨɻ Α͘ݴΘΕ·͢ɺɺɺ͚ͩͲ 

  22. Capybara 

  23. ‣ Webratޓ׵APIͷ͋ΔɺͳϥΠϒϥϦ ‣ υϥΠόΛ੾Γସ͑ͯJavaScript΋ಈ͔ͤΔΑ͏ʹɻ ‣ Selenium΋ߴϨϕϧAPIͰ࢖͑ΔΑ͏ʹͳͬͨɻ Capybara௒ϕϯϦɺͰ͢ΑͶ 

  24. JavaScript ·ͰؚΉΤϯυπʔΤϯυςετ͸
 ΋͏΋ͷ͍͢͝خ͍͠ɻ Capybara APIࣗମ΋ͲΜͲΜศརʹͳ͍ͬͯΔɻ JS͕ಈ͘֎෦ϒϥ΢βΛىಈ͢Δͷ͸ɺศར͚ͩͲ஗͍& Τϥʔ͕Θ͔ΓͮΒ͘ͳͬͨɻ ࣮ײͰ͖ͨ͜ͱ 

  25. ‣ RailsϒʔϜͱͱ΋ʹਓؾ্ঢɺߴػೳԽ͕ਐΉɻ ‣ shared example, subject, let, ϞοΫඪ४ఏڙ
 ‣ RSpec

    3ͰAPIͱ(งғؾ)͕มΘΔɻ ‣ test-unit ΍ power-assert ͷ੒ख़ͱͱ΋ʹɺxunit଒ͷ ݟ௚͕͠ਐΉɻ ಉ࣌ظʹ(ྑ͘΋ѱ͘΋)RSpecʹ΋େ͖ͳมԽ͕ 
  26. Capybara + X season 1 

  27. ‣ Turnip ‣ RSpecͷϥϯλΠϜͰɺGherkinελΠϧͷςετΛ
 ࣮ߦͰ͖Δɻ ‣ Cukeͷ൥ࡶϙΠϯτͩͬͨɺstep definitionsఆٛͱͷ
 ϚονϯάΛվળ͍ͯ͠Δɻ +

    RSpec + Gherkin 
  28. ‣ feature spec ‣ Capybara APIΛ௚઀࢖ͬͯɺΤϯυπʔΤϯυςετΛ ॻ͚ΔΑ͏ʹͨ͠ɻ ‣ Ұ෦ͷޠኮ(feature, scenario…)Λಋೖ͕ͨ͠ɺ͋͘·

    ͰRSpecͷϝιου໊ΤΠϦΞεʹͱͲ·Δɻ ‣ 2017೥࣌఺ͩͱɺ͜Ε͕ଟ਺೿͔ͳɻ + RSpec - Gherkin 
  29. ‣ σʔλͷηοτΞοϓ͕ͭΒ͍ɻ ‣ Τϯυ͔ΒผͷΤϯυ·Ͱɺ௕େͳΦϒδΣΫτάϥϑ͕ඞཁͱͳΓ͕ͪɻ ‣ ͕͔͔࣌ؒͬͨΓɺҙਤͤ͵ෆ׬શσʔλ͕Ͱ͖ͨΓɻ ‣ ૊Έ߹Θͤͷςετ͕ͭΒ͍ɻ ‣ shared

    exampleΛۦ࢖ͨ݁͠Ռɺݟ௨͕͠ѱ݅͘਺΋ଟ͘ͳΔɻ feature spec ͭΒ͍ܥ ͋Δ͋Δ 
  30. JavaScript ·ͰؚΉΤϯυπʔΤϯυςετ͸
 ΋͏΋ͷ͍͢͝خ͍͠ (΄Μ͜Ε) Α͍ΤϯυπʔΤϯυςετΛॻ͘ͷ͸೉͍͠ɻ υϝΠϯʹԊͬͨޠኮΛҭͯΔͷ΋ɻ ݕূ͢΂͖݁ՌͷݟۃΊ(ͳΜͱͳ͘Ξαʔτ)΋ɻ ࣮ײͰ͖ͨ͜ͱ 

  31.  https://speakerdeck.com/akiinyo/du-miyasuiendotuendotesutogashu-kitai?slide=5

  32. શϨΠϠΛ·ͱΊςετ͢Δʹ͸ศར ͚ͩͲɺେ͖ͯ͘஗͍ςετʹͳΓ͕ͪ ݁Ռͱͯ͠: 

  33. Capybara + X season 2 

  34. ‣ Appium ‣ Web͚ͩͰ͸ͳ͘ϞόΠϧΞϓϦ΋ࣗಈςετՄೳʹɻ ‣ Rails 5.1+ ͰCapybara͕ඪ४ʹɻ ‣ SystemTestCaseͱͯ͠࢖͑ΔΑ͏ʹͳΓɺRSpecͰ΋

    System Specͱͯ͠αϙʔτɻ ‣ Selenium υϥΠόͰheadless chrome΋࢖͑ΔΑ͏ʹɻ ͜Ε͔ΒͷΤϯυπʔΤϯυςετ 
  35. ·ͱΊ

  36. ‣ ࣗಈԽ͞Εͨ ‣ ΤϯυπʔΤϯυͷςετ͸ ‣ ͱͯ΋Α͍΋ͷͩ ࣮ײͰ͖ͨՁ஋ 

  37. ‣ ΤϯυπʔΤϯυςετ͸ ‣ େ͖ͯ͘ ‣ ஗ͯ͘ ‣ ॻ͘/ϝϯς͢Δͷ͕ΊΜͲ͍͘͞ɺςετʹͳΓ͕ͪ ࢒ͬͨ՝୊ 

  38. “ ࣗಈςετΛॻ͘ϓϥΫςΟε͸ੈͷ தʹཱ೿ʹࠜ෇͖ɺࣗ෼ͨͪͰࣗಈς ετΛॻ͘ͷ͕ʮ;ͭ͏ʯͳੈͷதʹ ͳΓ·ͨ͠ɻ͜Ε͸େ͖ͳલਐͰ͢ɻ — テスト駆動開発 「付録C」

  39. ‣ ໨ͷલͷϑΟʔνϟΛͲ͏͍͏γφϦΦʹͰ͖Δ͔ɺ
 ͦͷγφϦΦͰͷςετର৅͸Կ͔ɺΛΑ͘ߟ͑Δɻ ‣ ύϥϝλϥΠζυςετ(γφϦΦΞ΢τϥΠϯ)͸ɺ
 ΋͏ͪΐͬͱٕज़తʹ͏·͘΍Εͦ͏ͳؾ΋͢Δɻ ‣ υϝΠϯ΍νʔϜʹ߹ͬͨޠኮΛҭ͍ͯͯ͘ɻ ࢒ͬͨ՝୊ͱ޲͖߹͑Δͱ͍͍Ͱ͢ΑͶ 

  40. “ ςετۦಈ։ൃ͸ɺϓϩάϥϛϯάதͷෆ҆Λ ίϯτϩʔϧ͢Δख๏ͩɻ ུ 
 ʮ͜Ε͸ࠔ೉ͳ໰୊ͳͷͰɺ࠷ॳ͔Β͢΂ͯΛ ݟ௨ͤΔΘ͚Ͱ͸ͳ͍ʯͱ͍͏ਅͬ౰ͳײ֮ͷ ͜ͱͩɻ — テスト駆動開発

    「まえがき」
  41. ‣ ʮϑΟʔνϟશମʯ͸΋ͪΖΜ࠷ॳ͔Βݟ౉ͤͳ͍ɻ ‣ Ͱ΋ϑΟʔνϟͷࠜຊΛͪͬͪΌ͘࡞ͬͯɺͦͷςετΛ ௨͠ଓ͚Δ͜ͱ͸Ͱ͖ͦ͏ɻ ‣ ࠜຊ͸Կ͔ɺ͸ߟ͑Δɻ ‣ νʔϜͷޠኮ͕ҭ͍ͬͯΕ͹ɺ͍ͬͦ͏εϜʔζʹͳΓͦ͏ɻ ʮΤϯυπʔΤϯυʯ΁ͷద༻