Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Web-E2E-Testing-from-Ruby
Search
MOROHASHI Kyosuke
December 05, 2017
Programming
5
500
Web-E2E-Testing-from-Ruby
MOROHASHI Kyosuke
December 05, 2017
Tweet
Share
More Decks by MOROHASHI Kyosuke
See All by MOROHASHI Kyosuke
Identifying User Idenity
moro
6
10k
Simplicity on Rails -- RDB, REST and Ruby
moro
14
16k
ちょうどよい Rails E2E テスト/enough-good-rails-e2e-test
moro
5
2.3k
フレームワークを作らない方法/How NOT to build frameworks
moro
4
1.1k
全体がいい感じになるために、私たちRailsをホームにするWeb技術者ができること/let-our-whole-system-grow
moro
2
1.8k
フォームオブジェクトとの向き合い方/Grow Form Objects up
moro
1
1.9k
チームによるいきいきとしたソフトウェア開発/an-alive-team-grows-software
moro
3
3.3k
Joyful user foundation restructuring with Ruby
moro
9
19k
cookpad-17day-tech-internship-2017-git
moro
0
9.4k
Other Decks in Programming
See All in Programming
Click-free releases & the making of a CLI app
oheyadam
2
110
Quine, Polyglot, 良いコード
qnighy
4
640
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
870
受け取る人から提供する人になるということ
little_rubyist
0
230
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
最新TCAキャッチアップ
0si43
0
140
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
Featured
See All Featured
Building an army of robots
kneath
302
43k
KATA
mclloyd
29
14k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Into the Great Unknown - MozCon
thekraken
32
1.5k
A better future with KSS
kneath
238
17k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Embracing the Ebb and Flow
colly
84
4.5k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Transcript
Ruby && Webํ໘͔Βݟ͑ͨ ΤϯυπʔΤϯυςετͷ ྺ࢙ͱࢥ͍ग़ ॾڮګհ @moro
‣ (ࣸਅ) ղফͰ͖ͨෆ҆
Kyosuke MOROHASHI moro moro
None
લ࢙
‣ ΞϓϦέʔγϣϯͷܗΛ࡞Δͱςετڥ͕͍ͭͯ͘Δɻ ‣ test/models, test/controllers, test/views … ‣ ʮ୯ମʯςετ͕த৺ Ruby
on Rails
‣ & rspec_rails ‣ spec/models, spec/controllers, …. RSpec
‣ ϞσϧɾϏϡʔɾίϯτϩʔϥΛ౷߹(integrate)ͯ͠ ςετ͢Δɻ ‣ ୯ҰϦΫΤετʹ͓͍ͯɺΞϓϦέʔγϣϯͷ֤ϨΠϠ͕ ҙਤ௨Γ౷߹ͯ͠ಈ͔͘ɺΛςετ͢Δɻ ‣ ෳϦΫΤετʹΘͨΔڍಈ(͋ͷը໘͔Β͜ͷը໘ʹભҠͯͦ͠ΕΛೖྗ…) ςετͰ͖ͳ͍ɻ
Integration test / Request spec
‣ ϒϥβૢ࡞ΛࣗಈԽͯ͠ςετ͢Δ Selenium ͱɺ ‣ ਓؒͷૢ࡞Λهͯ͠ςετέʔεΛ࡞ͬͯ͘ΕΔ Selenium IDE Selenium &
Selenium IDE
‣ ϓϩδΣΫτϝϯόʔ͕ɺຖே࠷৽ͷίʔυΛνΣοΫΞ τͯ͠Ұ௨Γ৮ͬͯΈΔɻԿ͔͋Ε͙͢ʹ͢ɻ खಈͰͷܧଓతE2Eςετ
ෳϦΫΤετʹ·͕ͨΔɺϢʔβʔ͕࣮ࡍʹ͏ γφϦΦʹԊͬͨςετΑͦ͞͏ɻ ͜ͷ࣌Ͱ·ͩखಈςετɺ࣮ߦ͢Δͷ͕େมɻ Selenium IDEͰهͨ͠ςετ͙͢յΕΔɻ ࣮ײͰ͖ͨ͜ͱ
Webrat + Cucumber
‣ ΤϯυπʔΤϯυςετΛɺࣗવݴޠͰ͔͚Δɻ ‣ MVCϨΠϠ௨؏ & ෳΞΫγϣϯ ‣ ࣗવݴޠͰςετ͕͔͚Δɻ ‣ Gherkin
ϑΥʔϚοτ ‣ Given, When, Then / લఏɺ͠ɺͳΒ Cucumber
‣ Cucumber ͷόοΫΤϯυɺWebΞϓϦΛςετ͢Δͨ ΊͷϥΠϒϥϦɻ ‣ ηογϣϯ(cookie)ΛҾ͖ͭ͛Δ ‣ ʮෳϦΫΤετΛॱ൪ʹݺΜͩʯςετ͕͔͚ΔΑ͏ʹ ‣ ϦϯΫϑΥʔϜΛૢ࡞͢Δ(ͭΓͰ͑Δ)API͕͋ͬͨ
Webrat
‣ ࣗવݴޠͰॻ͍ͨ *.feature Λಈ͔ͨ͢ΊͷΈΛ step_definitions ͱͯ͠ॻ͘ɻ ‣ step_definitions ͷதRubyίʔυɻࣗવݴޠͱ ਖ਼نදݱͰϚονϯά͞ΕΔɻ
Cucumber + Webrat
None
‣ Gherkin ςΩετΛϓϩάϥϚͱɺϓϩάϥϚͰͳ͍ਓ ͱɺڞ༗Ͱ͖ͳ͍͔ͨΊͨ͠ɻ ‣ ϏδωεαΠυͷ༷ݕ౼/߹ҙʹ ‣ ݟੵΓ୯ҐʹͬͯΈͨΓ ‣ νʔϜͷ৽ϝϯόʔͷઆ໌ʹ
‣ ։ൃ࣌ͷҙࣝ߹Θͤʹ (feature͚ͩॻ͍ͨੜࣽ͑PRΛϨϏϡʔͨ͠Γ) ࢲͱCucumber
Web ͷɺγφϦΦهड़Ͱ͖ΔE2EࣗಈςετͷΈ Γͪΐ͏ΜΓɻ ޠͰॻ͍ͯ͋ΔͷɺͬͯΈΔͱΘ͔Γ͍͢ɻ ૿͕͑ͨʮຊޠϓϩάϥϛϯάʯʹͳͬͯ͠·͏ͱ ϓϩάϥϚʹͱͬͯࡶͳ͚ͩɻ ࣮ײͰ͖ͨ͜ͱ
“ ࣮ࡍʹɺͦΕΒඇٕज़ܥͷεςʔΫϗϧμʔ ʢརؔऀʣͱҰॹʹςετΛॻ͘ͱ͍͏ɺ ՍۭͷॴͰ͔͠ʹཱͪ·ͤΜɻ https://martinfowler.com/bliki/DynamicTyping.html ( http://bliki-ja.github.io/DynamicTyping/ )
‣ ඞͣ͠ʮॻ͍ͯʯΒΘͳ͚ΕͳΒͳ͍Θ͚Ͱͳ͍ɻ ‣ ಉ͡දݱͰεςʔΫϗϧμʔ͕Έͳڞ௨ཧղ͢Δͷ͕େࣄɻ ‣ ʮεςʔΫϗϧμʔʯʹͪΖΜɺ։ൃνʔϜؚ·ΕΔɻ ‣ ͦͷͨΊͷݴޠޠኮΛҭͯΔͷ͕େͩͬͨɻ Α͘ݴΘΕ·͢ɺɺɺ͚ͩͲ
Capybara
‣ WebratޓAPIͷ͋ΔɺͳϥΠϒϥϦ ‣ υϥΠόΛΓସ͑ͯJavaScriptಈ͔ͤΔΑ͏ʹɻ ‣ SeleniumߴϨϕϧAPIͰ͑ΔΑ͏ʹͳͬͨɻ CapybaraϕϯϦɺͰ͢ΑͶ
JavaScript ·ͰؚΉΤϯυπʔΤϯυςετ ͏ͷ͍͢͝خ͍͠ɻ Capybara APIࣗମͲΜͲΜศརʹͳ͍ͬͯΔɻ JS͕ಈ͘֎෦ϒϥβΛىಈ͢Δͷɺศར͚ͩͲ͍& Τϥʔ͕Θ͔ΓͮΒ͘ͳͬͨɻ ࣮ײͰ͖ͨ͜ͱ
‣ RailsϒʔϜͱͱʹਓؾ্ঢɺߴػೳԽ͕ਐΉɻ ‣ shared example, subject, let, ϞοΫඪ४ఏڙ ‣ RSpec
3ͰAPIͱ(งғؾ)͕มΘΔɻ ‣ test-unit power-assert ͷख़ͱͱʹɺxunitͷ ݟ͕͠ਐΉɻ ಉ࣌ظʹ(ྑ͘ѱ͘)RSpecʹେ͖ͳมԽ͕
Capybara + X season 1
‣ Turnip ‣ RSpecͷϥϯλΠϜͰɺGherkinελΠϧͷςετΛ ࣮ߦͰ͖Δɻ ‣ CukeͷࡶϙΠϯτͩͬͨɺstep definitionsఆٛͱͷ ϚονϯάΛվળ͍ͯ͠Δɻ +
RSpec + Gherkin
‣ feature spec ‣ Capybara APIΛͬͯɺΤϯυπʔΤϯυςετΛ ॻ͚ΔΑ͏ʹͨ͠ɻ ‣ Ұ෦ͷޠኮ(feature, scenario…)Λಋೖ͕ͨ͠ɺ͋͘·
ͰRSpecͷϝιου໊ΤΠϦΞεʹͱͲ·Δɻ ‣ 2017࣌ͩͱɺ͜Ε͕ଟ͔ͳɻ + RSpec - Gherkin
‣ σʔλͷηοτΞοϓ͕ͭΒ͍ɻ ‣ Τϯυ͔ΒผͷΤϯυ·ͰɺେͳΦϒδΣΫτάϥϑ͕ඞཁͱͳΓ͕ͪɻ ‣ ͕͔͔࣌ؒͬͨΓɺҙਤͤ͵ෆશσʔλ͕Ͱ͖ͨΓɻ ‣ Έ߹Θͤͷςετ͕ͭΒ͍ɻ ‣ shared
exampleΛۦͨ݁͠Ռɺݟ௨͕͠ѱ݅͘ଟ͘ͳΔɻ feature spec ͭΒ͍ܥ ͋Δ͋Δ
JavaScript ·ͰؚΉΤϯυπʔΤϯυςετ ͏ͷ͍͢͝خ͍͠ (΄Μ͜Ε) Α͍ΤϯυπʔΤϯυςετΛॻ͘ͷ͍͠ɻ υϝΠϯʹԊͬͨޠኮΛҭͯΔͷɻ ݕূ͖݁͢ՌͷݟۃΊ(ͳΜͱͳ͘Ξαʔτ)ɻ ࣮ײͰ͖ͨ͜ͱ
https://speakerdeck.com/akiinyo/du-miyasuiendotuendotesutogashu-kitai?slide=5
શϨΠϠΛ·ͱΊςετ͢Δʹศར ͚ͩͲɺେ͖͍ͯ͘ςετʹͳΓ͕ͪ ݁Ռͱͯ͠:
Capybara + X season 2
‣ Appium ‣ Web͚ͩͰͳ͘ϞόΠϧΞϓϦࣗಈςετՄೳʹɻ ‣ Rails 5.1+ ͰCapybara͕ඪ४ʹɻ ‣ SystemTestCaseͱͯ͑͠ΔΑ͏ʹͳΓɺRSpecͰ
System Specͱͯ͠αϙʔτɻ ‣ Selenium υϥΠόͰheadless chrome͑ΔΑ͏ʹɻ ͜Ε͔ΒͷΤϯυπʔΤϯυςετ
·ͱΊ
‣ ࣗಈԽ͞Εͨ ‣ ΤϯυπʔΤϯυͷςετ ‣ ͱͯΑ͍ͷͩ ࣮ײͰ͖ͨՁ
‣ ΤϯυπʔΤϯυςετ ‣ େ͖ͯ͘ ‣ ͯ͘ ‣ ॻ͘/ϝϯς͢Δͷ͕ΊΜͲ͍͘͞ɺςετʹͳΓ͕ͪ ͬͨ՝
“ ࣗಈςετΛॻ͘ϓϥΫςΟεੈͷ தʹཱʹ͖ࠜɺࣗͨͪͰࣗಈς ετΛॻ͘ͷ͕ʮ;ͭ͏ʯͳੈͷதʹ ͳΓ·ͨ͠ɻ͜Εେ͖ͳલਐͰ͢ɻ — テスト駆動開発 「付録C」
‣ ͷલͷϑΟʔνϟΛͲ͏͍͏γφϦΦʹͰ͖Δ͔ɺ ͦͷγφϦΦͰͷςετରԿ͔ɺΛΑ͘ߟ͑Δɻ ‣ ύϥϝλϥΠζυςετ(γφϦΦΞτϥΠϯ)ɺ ͏ͪΐͬͱٕज़తʹ͏·͘Εͦ͏ͳؾ͢Δɻ ‣ υϝΠϯνʔϜʹ߹ͬͨޠኮΛҭ͍ͯͯ͘ɻ ͬͨ՝ͱ͖߹͑Δͱ͍͍Ͱ͢ΑͶ
“ ςετۦಈ։ൃɺϓϩάϥϛϯάதͷෆ҆Λ ίϯτϩʔϧ͢Δख๏ͩɻ ུ ʮ͜ΕࠔͳͳͷͰɺ࠷ॳ͔Βͯ͢Λ ݟ௨ͤΔΘ͚Ͱͳ͍ʯͱ͍͏ਅͬͳײ֮ͷ ͜ͱͩɻ — テスト駆動開発
「まえがき」
‣ ʮϑΟʔνϟશମʯͪΖΜ࠷ॳ͔Βݟͤͳ͍ɻ ‣ ͰϑΟʔνϟͷࠜຊΛͪͬͪΌ͘࡞ͬͯɺͦͷςετΛ ௨͠ଓ͚Δ͜ͱͰ͖ͦ͏ɻ ‣ ࠜຊԿ͔ɺߟ͑Δɻ ‣ νʔϜͷޠኮ͕ҭ͍ͬͯΕɺ͍ͬͦ͏εϜʔζʹͳΓͦ͏ɻ ʮΤϯυπʔΤϯυʯͷద༻