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
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
190
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.5k
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
690
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
230
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
2
760
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
160
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
170
Security_for_introducing_eBPF
kentatada
0
110
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
100
Discord Bot with AI -for English learners-
xin9le
1
120
eBPF Deep Dive: Architecture and Safety Mechanisms
takehaya
12
1.4k
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
990
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Practical Orchestrator
shlominoach
186
10k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
KATA
mclloyd
29
14k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Bash Introduction
62gerente
608
210k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Typedesign – Prime Four
hannesfritz
40
2.4k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
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」
‣ ͷલͷϑΟʔνϟΛͲ͏͍͏γφϦΦʹͰ͖Δ͔ɺ ͦͷγφϦΦͰͷςετରԿ͔ɺΛΑ͘ߟ͑Δɻ ‣ ύϥϝλϥΠζυςετ(γφϦΦΞτϥΠϯ)ɺ ͏ͪΐͬͱٕज़తʹ͏·͘Εͦ͏ͳؾ͢Δɻ ‣ υϝΠϯνʔϜʹ߹ͬͨޠኮΛҭ͍ͯͯ͘ɻ ͬͨ՝ͱ͖߹͑Δͱ͍͍Ͱ͢ΑͶ
“ ςετۦಈ։ൃɺϓϩάϥϛϯάதͷෆ҆Λ ίϯτϩʔϧ͢Δख๏ͩɻ ུ ʮ͜ΕࠔͳͳͷͰɺ࠷ॳ͔Βͯ͢Λ ݟ௨ͤΔΘ͚Ͱͳ͍ʯͱ͍͏ਅͬͳײ֮ͷ ͜ͱͩɻ — テスト駆動開発
「まえがき」
‣ ʮϑΟʔνϟશମʯͪΖΜ࠷ॳ͔Βݟͤͳ͍ɻ ‣ ͰϑΟʔνϟͷࠜຊΛͪͬͪΌ͘࡞ͬͯɺͦͷςετΛ ௨͠ଓ͚Δ͜ͱͰ͖ͦ͏ɻ ‣ ࠜຊԿ͔ɺߟ͑Δɻ ‣ νʔϜͷޠኮ͕ҭ͍ͬͯΕɺ͍ͬͦ͏εϜʔζʹͳΓͦ͏ɻ ʮΤϯυπʔΤϯυʯͷద༻