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
20171002Testing
Search
Shigure Shimotori
October 02, 2017
Programming
2
1.8k
20171002Testing
#orecon_ios #ios_test_night
Shigure Shimotori
October 02, 2017
Tweet
Share
More Decks by Shigure Shimotori
See All by Shigure Shimotori
Synchronizationを支える技術
s_shimotori
1
180
1人で挑むSwiftコンパイラ 〜型システム入門編〜
s_shimotori
0
620
英語
s_shimotori
1
550
Parallel Socket Communication in Swift
s_shimotori
1
680
UIColor Anatomy
s_shimotori
1
2.4k
UIColor Cluster
s_shimotori
1
700
iOSDC Japan 2019 60 mins for color
s_shimotori
5
3.7k
wwdc19
s_shimotori
2
340
SE-0246 Generic Math(s) Functions
s_shimotori
2
2.4k
Other Decks in Programming
See All in Programming
快速入門可觀測性
blueswen
0
370
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
460
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
390
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
790
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
260
Beyond ORM
77web
7
900
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
110
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
MCP with Cloudflare Workers
yusukebe
2
220
선언형 UI에서의 상태관리
l2hyunwoo
0
170
Featured
See All Featured
Faster Mobile Websites
deanohume
305
30k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Designing Experiences People Love
moore
138
23k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
How STYLIGHT went responsive
nonsquared
95
5.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Transcript
Զίϯ Vol.1 / Day.1 (iOSDC Japan 2017 #1312) ࠓͦ͜ςετͷؾ࣋ͪΛߟ͑Δ @S_Shimotori
ͩΕ • @S_Shimotori / @S_Shimotori_pub • ৬ۀ: ֶੜ • GCςετઐͰͳ͍
• iOSDCͰʮARC vs. GCʁARC in GCʁʯΛΓ·ͨ͠ • ࠓiOS Test NightͰདྷ·ͨ͠
ษڧձΛΓา͍ͯͬͨ͜ͱ
ࣾձਓ ςετΛॻ͔ͳ͍ʂʂ
ͱ͍͏͔୭ςετΛॻ͔ͳ͍ • ࣾձਓςετΛॻ͔ͳ͍ • ͕࣌ؒͳ͍ • ͦΜͳ͜ͱΑΓͬ͞͞ͱϦϦʔε͠Α͏ͥʂ • ֶੜςετΛॻ͔ͳ͍(ࢲΛؚΉ) •
ͦͦςετͬͯԿͰ͔͢ʁ • ͦΕҎલʹΞϓϦ։ൃͬͯԿͰ͔͢ʁ • ςετͳΜ͔ॻ͍ͯͨΒ՝ఏग़ʹؒʹ߹Θͳ͍ ʘ(^o^)ʗ Φɹϫɹλ
ςετΛऔΓר͘ݱঢ় • ςετΛֶͿػձ͕ͳ͍ • ςετΛ࣮ફ͢Δػձ͕ͳ͍ • ςετηογϣϯޙͷ࠙ձͰఘΊͷݴ༿
ͱ͍͏Θ͚Ͱ
ຊηογϣϯͰѻ͏͜ͱ • ςετςετͬͯɼԿ͕ςετ͔Θ͔ͬͯΔͷʁ • ͖ͬͱςετ໘ന͍ͣͳΜͩ • ςετؔͰݸਓతʹ໘ന͍ͱࢥͬͨϙΠϯτ
ςετςετͬͯɼ Կ͕ςετ͔Θ͔ͬͯΔͷʁ
XCTest.framework͕ݴ͏ͱ͜Ζͷςετ • ςετυΩϡϝϯτͰΑ͘ఆ͕ٛޠΒΕΔ • XCTestͷ߹: assertion / ςετ݁Ռͷه / ύϑΥʔϚϯεͷଌఆ
/ UIૢ࡞[1] [1] https://developer.apple.com/documentation/xctest
͜ΕͰඞཁेʁ
ςετͱͦͦԿऀ͔ʁ(1/2) • ސ٬͕ཉ͍͠ͷΛ࡞Ε͔͔ͨ֬ΊΔख๏ͷ1ͭ • XCTestͷڍ͛ͨྫ͞Βʹͦͷதͷ΄ΜͷҰ෦ • ςετҎ֎ͷखஈͱͯ͠ϞσϧݕࠪͳͲ͕͋Δ ↓͍ͭͷΞϨ↓
ςετͱͦͦԿऀ͔ʁ(2/2) • ςετରͷܽؕΛ୳͢Ұ࿈ͷϓϩηε • ํܭըΛཱͯΔͱ͜Ζ͔Β࢝·͍ͬͯΔ • ձࣾશମͷํʁຊϓϩδΣΫτͰͷςετܭըʁ • ࣮ࡍʹϓϩάϥϜΛ࣮ߦ͢ΔͱݶΒͳ͍ •
ίʔυϨϏϡʔɹ ཱͩͬͯͳςετʂ • ͍Ζ͍Ζͳςετͷछྨɺ͚ํ͕͋Δ • ੩తɺಈత • ύϑΥʔϚϯεɺηΩϡϦςΟɺetc…
Apple͕ݴ͏ͱ͜Ζͷςετ • Testing with Xcode[2] • Xcodeͷ͍ํXCTest.frameworkͷ • ςετ͍͢͠ίʔυͱԿ͔ʹ͍ͭͯड़ΒΕ͍ͯΔ •
App Testing Guide[3] • ςετͷखॱΞϓϦʹෆ۩߹Λى͜͢ओͳݪҼҰཡͳͲ • ؔ࿈͢ΔଞͷΨΠυͷϦϯΫ͕๛ [2] https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/ [3] https://developer.apple.com/library/content/technotes/tn2431/_index.html XCTest.framework͕શͯͰͳ͍ʂ
ͭ·Γʁ
Θ͔ͨ͠Βͷ͓ئ͍ • ςετΛͯ͠ͳ͍ਓͳͲ͍ͳ͍ʂ • ͋ͳͨͷྡͷ੮ͷਓ͖ͬͱᘳʹͬͯͳ͍Α • iOS Test Nightʹ͓͍ͯಉ͡ •
fastlaneᘳ͡Όͳ͍ͬͯgiginet͞Μ͕ݴͬͯͨ[4] • Կ͔औΓΉ͜ͱ͕Ͱ͖ͨΒڞ༗͍ͯͩ͘͠͞ • ݶΒΕͨਓ݄ͰطͷͷΛಋೖ͢Δ͜ͱݟͷ1ͭ [4] https://speakerdeck.com/giginet/fastlane-contributordakedohe-kazhi-wen-aru
࣍
͖ͬͱςετ໘ന͍ͣͳΜͩ
ςετʮ͜͏ॻ͍ͯ΄͍͠ʯͱࢥ͍ͬͯΔ͔ • ςετʹن͕֨͋Δ • XCTest͕Ͱ͖Δ͜ͱ • iOS༻ͷϥΠϒϥϦͷςετΛݟͯΈΔ • ͦͷ΄͔ɺԶ͕ؾʹͳΔςετɹུͯ͠……ͳΜͩΖ͏
ςετʹن͕֨͋Δ
ςετʹن͕֨͋Δ • ISO/IEC/IEEE 29119[5][6][7][8][9] • ιϑτΣΞςετͷࠃࡍج४Λఆٛͨ͠γϦʔζ5ຊͩͯ • ਤ͕ڵຯਂ͍ • ମ੍උͷ͖ͨͨɺ༻ޠूͱͯ͑͠Δ…͔
• ISO/IEC TR 19759:2015[10] • ιϑτΣΞશൠ • ଏʹSWEBOK • ֶߍ͕ISO/IECऔͬͯͳ͍ΜͰ͢୭͔ങͬͯ͋ͱC++ཉ͍͠(?) [5]http://ieeexplore.ieee.org/document/6588537/ [6]http://ieeexplore.ieee.org/document/6588543/ [7]http://ieeexplore.ieee.org/document/6588540/ [8]http://ieeexplore.ieee.org/document/7346375/ [9]http://ieeexplore.ieee.org/document/7750539/ [10]https://www.iso.org/standard/67604.html
XCTest͕Ͱ͖Δ͜ͱ
XCTestʹ͋Δͷ • Test Cases and Test Methods • Test Assertions
• Asynchronous Tests • UI Tests • Activities and Attachments • Test Execution : XCTestͷجຊ෦ : Darwinಛ༗orޙ͚
xUnitੜ͔ΒXCTestʹࢸΔ·Ͱ • 1994ࠒʹK. Beck͕SUnitΛ࡞ͬͨͷ͕࢝·Γ • scripted testʹқ͍༷ͯͨ͠͝ࢠ • JUnitK. BeckΒ͕SUnitΛJavaʹҠ২ͨ͠ͷ
• Python unittestJUnitͷੜ • JUnit4ΞϊςʔγϣϯΛ࠾༻͢ΔͳͲมΘͬͨ ڭ͑ͯৄ͍͠ਓ • 2005ͨͿΜ ɺXcode2.1͕OCUnitΛ࠾༻ • Objective-C༻ͷϑϨʔϜϫʔΫ • 2013ɺXcode5.0͕XCTestΛ࠾༻
K. Beck͞ΜΦεεϝͷΓ͔ͨ • ΫϥεຖʹϢχοτςετΛॻ͖͘ • ৼΔ͍͕୯७ͳͷ͔Βઓ͍ͯ͜͠͏ • ౷߹ςετผͷਓ͕࣮͢Δ͖ • 25ʙ50%ͷ࣌ؒΛςετ։ൃʹ͏͖
xUnitʹ͓͚Δ࣮ύλʔϯ • Fixture • TestCasesetUpΛͬͯڞ௨ͷςετڥΛ༻ҙ • Test Case • ࣮ɺೖྗɺظ݁Ռͷू߹Λ༻ҙ
• ޓ͍ͷ݁ՌʹӨڹ͕ͳ͍ͷ͕ϛι • Check • ࣮݁Ռͱظ݁ՌΛൺֱ • ࣦഊͨ͠Β࣍ͷtest caseͷॲཧʹҠΔ • Test Suite • test caseͷू߹Λཧ͢Δ
XCTestͷಛ • ෳࡶͳܧঝؔʹ͋ΔΫϥε͕ఏڙ͞Ε͍ͯΔ • ࣗ༝ʹsetUp/tearDown͍ͤͨ͞ΜͰ͔͢Ͷʁ • ͪΖΜXCTestCase͚ͩͰςετՄೳ
ৄ͘͠WebͰ
XCTest͕ੜ·Ε͔ͯΒ • 2014ɺXcode6.0ʹύϑΥʔϚϯεςετͱ ඇಉظॲཧςετΛՃ • 2015ɺXcode7.0ʹUIςετՃ • Instruments UIAutomation͔ΒͷҠߦ •
2016ɺ • 2017ɺXcode8.3/9.0Ͱࡉ͔͍Ճͱमਖ਼
iOS༻ͷϥΠϒϥϦͷ ςετΛݟͯΈΔ
ྲྀߦΓͷϥΠϒϥϦΛݟͯΈΑ͏ʂ • ௐࠪର: ʮ2017Λࢧ͢ΔϥΠϒϥϦʯ[11]ଞ • UIϥΠϒϥϦͷςετ • εΫγϣͰݟ͔͑ͨΛ͔֬ΊΔ • ௨৴ςετ
• ϓϩδΣΫτͷςετํ • ςετίʔυࣗಈੜ • ͓·͚: SPM༻ͷॲஔ [11]https://medium.com/app-coder-io/33-ios-open-source-libraries-that-will-dominate-2017-4762cf3ce449
೦ͳ͓Βͤ • ਓؾͰظגͷϥΠϒϥϦ != ͔ͬ͠ΓςετࡁΈ • Δਓ͕͍ͳ͍͔Βʁςετ͢Δͷ͕͍͔͠Βʁ • ObjC൛Ͱςετͯ͠Swift൛Ͱςετͯ͠ͳ͍ྫ͋Δ •
όάͳ͠Ͱಈ࡞͢Δอূͳ͍ • UI͕ਓؒͷʹݟ͑Δܗʹͳ͍ͬͯΔ͔Ͳ͏͔ಉ༷ • ࣮ࡍʹಈ͔ͯ͠Έͳ͍͜ͱʹΘ͔Βͳ͍ https://github.com/nickoneill/PermissionScope https://github.com/ViccAlexander/Chameleon https://github.com/krzyzanowskim/Natalie https://github.com/dani-gavrilov/GDPerformanceView-Swift
UIϥΠϒϥϦͷςετ • UIςετ͍ͯ͠ͳ͍͜ͱ͕ଟ͍ • ʮσʔλΛ༩͑ΔˠཁૉΛΞαʔγϣϯͰ֬ೝʯ͕ఆ൪ • ࣮ࡍͲ͏ݟ͑Δ͔Α͘Θ͔Βͳ͍ https://github.com/Instagram/IGListKit/blob/d9a89c9b00aa1a9537a24d9affb6919f83065f65/Tests/IGListAdapterE2ETests.m
εΫγϣͰݟ͔͑ͨΛ͔֬ΊΔ • ࣮ࡍͷݟͨ·ͰνΣοΫ͍ͯ͠Δ͜ͱ͋Δ • ݁ہਓྗͰࢹ • εΫγϣΛࡱΔํ๏3छ • facebook/ios-snapshot-test-case •
fastlane/fastlane/tree/master/snapshot • XCUIScreenshot https://github.com/danielgindi/Charts/blob/d300d6d332afa2e790fd616e5a8326e815b0e1f0/Tests/Charts/BarChartTests.swift
௨৴Λߦ͏ϥΠϒϥϦͷςετ • ௨৴ઌͲ͔͜Βௐୡͯ͘͠Δͷ͔ʁ • ελϒΛ༻͍Δ • ishkawa/APIKit • AliSoftware/OHHTTPStubs→ಠ࣮ࣗ •
ౖͬͯΒΕͳ͍αʔό • onevcat/Hedwig • ϩʔΧϧˠϥΠϒϥϦ։ൃऀͷϝʔϧαʔόʔ(ʁ) • Alamofire/Alamofire • httpbin(1)
ϓϩδΣΫτͷςετํ(mxcl/PromiseKit) • ݩΛͨͲΕPromises/A+ • ཁ͔݅Βςετ·Ͱ༻ҙ͞Ε͍ͯΔ • ςετʹ߹֨͢ΕPromises/A+ͷϩΰΛܝࣔͰ͖Δ • ͜ΕͧBDD •
PromiseKitͰϓϩδΣΫτ४ڌͷςετͱ ಠࣗͷςετͷ྆ํΛ͓͜ͳ͍ͬͯΔ • ࣗલͷdescribeϝιουΛۦ https://github.com/mxcl/PromiseKit/tree/master/Tests/A%2B https://github.com/promises-aplus/promises-tests/tree/master/lib/tests
ϓϩδΣΫτͷςετํ(ReactiveX/RxSwift) • ݩΛͨͲΕReactiveX • ݟ͔ͭΓ·ͤΜͰͨ͠… • ݟ͚ͭͨΒڭ͑ͯʂ
ςετίʔυࣗಈੜ • ςετίʔυΛࣗಈੜͯ͠खؒΛল͘ • ͦΕͧΕ͕ಠࣗʹੜϓϩάϥϜΛ࡞ͬͯΓ͘Γ͍ͯ͠Δ • Ҿ͕ҧ͏͚ͩͷϝιου͕ଟ͍࣌ʹʹཱͭ • ReactiveX/RxSwift •
ؔςετࣗಈੜ • thoughtbot/Curry • ؔΛࣗಈੜ(ςετͳ͠)
(͓·͚)SPM༻ͷॲஔ • AlamofireͳͲ • ύοέʔδ͔ΒςετΛ·Δ͝ͱআ֎ • RxSwiftͳͲ • exclude#if os(Linux)ΛͬͯCocoaΛִ
• APIKit • OHHTTPStub(SPMඇରԠ)͔ΒࣗલελϒʹΓ͑
·ͱΊ
·ͱΊ • ͬͱςετʹରͯ͠ϙδςΟϒʹ͍͖·ͤΜ͔ʁ • ݟΛڞ༗͍ͯͩ͘͠͞ʂ • ςετ͍Ζ͍ΖͳऔΓΈ͕͋ͬͯ໘ന͍ʂ • ࣗಈςετΛ͠ͳ͍ʹͯ͠ɺ͕ࣝ͋ͬͯଛ͠ͳ͍ •
ޙͰςετΛಋೖ͍͢͠ઃܭʹ͍ͨ͠Ͱ͢Ͷ
ͨͷ͍͠ࢀߟจݙ • Kent BeckʰBeck Testing Frameworkʱ<https://web.archive.org/web/20150315073817/http://www.xprogramming.com/ testfram.htm>ɼ(ࢀর2017-9-27) • Apple Inc.ʰXcode
Release Notesʱ<https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/>ɼ(ࢀ র2017-9-27) • Python Software Foundationʰ26.4. unittest — ϢχοτςετϑϨʔϜϫʔΫ — Python 3.6.1 υΩϡϝϯτʱ<https://docs.python.jp/ 3/library/unittest.html>ɼ(ࢀর2017-9-27) • খḺ૯߹σβΠϯࣄہʰʲ༻OKʳອը෩ϑϦʔૉࡐʮूதઢʯฤ 28ݸʲPNGɾAiʢIllustratorʣʳ | খḺ૯߹σβΠϯࣄہʛ ϗʔϜϖʔδ੍࡞ɾσβΠϯɾLINEελϯϓ੍࡞ʱ<http://otarunet.com/it/webdesign/comic-material-effect01/>ɼ(ࢀর2017-9- 18)ɽ