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
510
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
9
13k
Simplicity on Rails -- RDB, REST and Ruby
moro
14
17k
ちょうどよい 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.9k
フォームオブジェクトとの向き合い方/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
Refactor your code - refactor yourself
xosofox
1
260
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Haze - Real time background blurring
chrisbanes
1
500
Jakarta EE meets AI
ivargrimstad
0
230
Full stack testing :: basic to basic
up1
1
930
103 Early Hints
sugi_0000
1
220
快速入門可觀測性
blueswen
0
320
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
130
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
What's in a price? How to price your products and services
michaelherold
243
12k
How to Ace a Technical Interview
jacobian
276
23k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
How STYLIGHT went responsive
nonsquared
95
5.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
We Have a Design System, Now What?
morganepeng
51
7.3k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Navigating Team Friction
lara
183
15k
Building Adaptive Systems
keathley
38
2.3k
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」
‣ ͷલͷϑΟʔνϟΛͲ͏͍͏γφϦΦʹͰ͖Δ͔ɺ ͦͷγφϦΦͰͷςετରԿ͔ɺΛΑ͘ߟ͑Δɻ ‣ ύϥϝλϥΠζυςετ(γφϦΦΞτϥΠϯ)ɺ ͏ͪΐͬͱٕज़తʹ͏·͘Εͦ͏ͳؾ͢Δɻ ‣ υϝΠϯνʔϜʹ߹ͬͨޠኮΛҭ͍ͯͯ͘ɻ ͬͨ՝ͱ͖߹͑Δͱ͍͍Ͱ͢ΑͶ
“ ςετۦಈ։ൃɺϓϩάϥϛϯάதͷෆ҆Λ ίϯτϩʔϧ͢Δख๏ͩɻ ུ ʮ͜ΕࠔͳͳͷͰɺ࠷ॳ͔Βͯ͢Λ ݟ௨ͤΔΘ͚Ͱͳ͍ʯͱ͍͏ਅͬͳײ֮ͷ ͜ͱͩɻ — テスト駆動開発
「まえがき」
‣ ʮϑΟʔνϟશମʯͪΖΜ࠷ॳ͔Βݟͤͳ͍ɻ ‣ ͰϑΟʔνϟͷࠜຊΛͪͬͪΌ͘࡞ͬͯɺͦͷςετΛ ௨͠ଓ͚Δ͜ͱͰ͖ͦ͏ɻ ‣ ࠜຊԿ͔ɺߟ͑Δɻ ‣ νʔϜͷޠኮ͕ҭ͍ͬͯΕɺ͍ͬͦ͏εϜʔζʹͳΓͦ͏ɻ ʮΤϯυπʔΤϯυʯͷద༻