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
事業成長を爆速で進めてきたプロダクトエンジニアたちの成功談・失敗談
nealle
3
1.4k
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
160
Thoughts and experiences on Rust and TypeScript
unvalley
2
220
talk-with-local-llm-with-web-streams-api
kbaba1001
0
170
命名をリントする
chiroruxx
1
360
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
230
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
120
From Translations to Multi Dimension Entities
alexanderschranz
2
120
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
390
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
160
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
420
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
Featured
See All Featured
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Producing Creativity
orderedlist
PRO
341
39k
Building Adaptive Systems
keathley
38
2.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
KATA
mclloyd
29
14k
A better future with KSS
kneath
238
17k
Making the Leap to Tech Lead
cromwellryan
133
9k
Unsuck your backbone
ammeep
669
57k
Why Our Code Smells
bkeepers
PRO
335
57k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
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」
‣ ͷલͷϑΟʔνϟΛͲ͏͍͏γφϦΦʹͰ͖Δ͔ɺ ͦͷγφϦΦͰͷςετରԿ͔ɺΛΑ͘ߟ͑Δɻ ‣ ύϥϝλϥΠζυςετ(γφϦΦΞτϥΠϯ)ɺ ͏ͪΐͬͱٕज़తʹ͏·͘Εͦ͏ͳؾ͢Δɻ ‣ υϝΠϯνʔϜʹ߹ͬͨޠኮΛҭ͍ͯͯ͘ɻ ͬͨ՝ͱ͖߹͑Δͱ͍͍Ͱ͢ΑͶ
“ ςετۦಈ։ൃɺϓϩάϥϛϯάதͷෆ҆Λ ίϯτϩʔϧ͢Δख๏ͩɻ ུ ʮ͜ΕࠔͳͳͷͰɺ࠷ॳ͔Βͯ͢Λ ݟ௨ͤΔΘ͚Ͱͳ͍ʯͱ͍͏ਅͬͳײ֮ͷ ͜ͱͩɻ — テスト駆動開発
「まえがき」
‣ ʮϑΟʔνϟશମʯͪΖΜ࠷ॳ͔Βݟͤͳ͍ɻ ‣ ͰϑΟʔνϟͷࠜຊΛͪͬͪΌ͘࡞ͬͯɺͦͷςετΛ ௨͠ଓ͚Δ͜ͱͰ͖ͦ͏ɻ ‣ ࠜຊԿ͔ɺߟ͑Δɻ ‣ νʔϜͷޠኮ͕ҭ͍ͬͯΕɺ͍ͬͦ͏εϜʔζʹͳΓͦ͏ɻ ʮΤϯυπʔΤϯυʯͷద༻