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
What is iOSSnapshotTestCase
Search
Shingo Tamaki
August 24, 2018
Technology
1
890
What is iOSSnapshotTestCase
Description of how to use iOSSnapshotTestCase.
Shingo Tamaki
August 24, 2018
Tweet
Share
More Decks by Shingo Tamaki
See All by Shingo Tamaki
沖縄モバイルアプリ開発勉強会#1
tamaki
0
82
iOSアプリ開発を始めよう
tamaki
0
120
詳解xcresult.pdf
tamaki
0
290
メルペイでのリグレッションテスト自動化推進のこれまでとこれから
tamaki
0
680
What do you want to test with UI Test v2
tamaki
2
840
JPQRによって変わる日本のQRコード決済
tamaki
0
240
What's New in Testing
tamaki
1
58
What do you want to test with UI Test
tamaki
5
1.8k
How to control state in UI Test
tamaki
4
2.5k
Other Decks in Technology
See All in Technology
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
170
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
1
2.3k
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
Engineer Career Talk
lycorp_recruit_jp
0
150
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
130
【若手エンジニア応援LT会】ソフトウェアを学んできた私がインフラエンジニアを目指した理由
kazushi_ohata
0
150
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Into the Great Unknown - MozCon
thekraken
32
1.5k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Producing Creativity
orderedlist
PRO
341
39k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
A Modern Web Designer's Workflow
chriscoyier
693
190k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Code Review Best Practice
trishagee
64
17k
Transcript
iOSSnapshotTestCase ͰϏϡʔͷςετΛߦ͏
ࣗݾհ • ۄ৴ޛ • iOS Engineer • iOSDC2018Ͱελοϑ͠·͢
iOSSnapshotTestCaseͱ View based testingΛߦ͏ͨΊͷπʔϧ ݩFBSnapshotTestCaseͰɺͱͱFacebook Ϗϡʔͷը૾Λ͖߹ΘͤͯมߋҰக͢Δ͔Λςετ͢Δػೳ ͕͋Γ·͢ɻ
ḪΔࣄҰલ
ḪΔࣄҰલ
ผͷखஈΛݕ౼ͯ͠ΈͨΓ WiremockΛͬͨUIςετ https://speakerdeck.com/tamaki/wiremockdexing-uuitesuto
σϝϦοτ͋Γ·ͨ͠ • XCUITestͷ࣮ߦ࣌ؒ • XCUITestͰը໘ͷঢ়ଶΛ࡞Δखؒ
ͱࢥͬͨΒ...
iOSSnapshotTestCaseͱͯ͠෮׆ Uber͕Ҿ͖ܧ͙ܗͰ෮׆ https://github.com/uber/ios-snapshot-test-case
࠶ͼ͍࢝ΊΔࣄʹ͠·ͨ͠ɻ
iOSSnapshotTestCase ͷ͍ํ
Πϯετʔϧ target "Tests" do use_frameworks! pod 'iOSSnapshotTestCase' end
ઃఆ • FBREFERENCEIMAGEDIR: $(SOURCEROOT)/$ (PROJECT_NAME)Tests/ReferenceImages • IMAGEDIFFDIR: $(SOURCEROOT)/$(PROJECTNAME)Tests/ FailureDiffs
ςετ࡞ FBSnapshotTestCaseΛܧঝͨ͠ςετέʔεΛ࡞͠·͢ɻ class iOSSnapshotTestCaseSampleTests: FBSnapshotTestCase { }
ςετϝιου࡞ FBSnapshotVerifyViewͰରͷϏϡʔΛνΣοΫ͠·͢ɻ ରͷϏϡʔͷαΠζCGRect(x:y:width:height)ͳͲͰࢦఆ͠ ͓͖ͯ·͠ΐ͏ɻ view.frame = CGRect(x: 0, y: 0,
width: 768, height: 1024) FBSnapshotVerifyView(view, identifier: "view id")
ϦϑΝϨϯεը૾ͷ࡞ recordMode͕trueͷͰςετΛ࣮ߦ͢ΔͱϦϑΝϨϯε༻ը૾ ͕ੜ͞Ε·͢ɻ override func setUp() { super.setUp() recordMode =
true }
ϦϑΝϨϯεը૾ ReferenceImages_64ͷԼʹςετλʔήοτ໊.ςετέʔ ε໊ͷσΟϨΫτϦͱɺ ͦͷԼʹ͖߹ΘͤʹඞཁͱͳΔࢀর༻ը૾͕࡞͞Ε·͢ɻ iOSSnapshotTestCaseSampleTests/ ├── Info.plist ├── ReferenceImages_64 │
└── iOSSnapshotTestCaseSampleTests.TopScreenSnapshotTests │ └──
[email protected]
└── TopScreenSnapshotTests.swift
ϦϑΝϨϯεը૾
ςετͷ࣮ߦ recordModeΛfalseʹ͢ΔࣄΛΕͳ͍Α͏ʹɻ override func setUp() { super.setUp() recordMode = false
}
ςετ݁Ռ
ը໘͕มߋ͠ςετΛ࣮ߦ͢Δͱ... ૂ͍௨Γςετࣦഊ͠·ͨ͠Ͷʁ
FailureDiffsΛݟͯΈΑ͏ ├── FailureDiffs │ └── iOSSnapshotTestCaseSampleTests.TopScreenSnapshotTests │ ├──
[email protected]
│
├──
[email protected]
│ └──
[email protected]
├── Info.plist ├── ReferenceImages_64 │ └── iOSSnapshotTestCaseSampleTests.TopScreenSnapshotTests │ └──
[email protected]
└── TopScreenSnapshotTests.swift
FailureDiffsͷத FailureDiffsσΟϨΫτϦ͕ੜ͞Εɺ3ͭͷϑΝΠϧ͕ೖͬͯ· ͢ file name description diff_*.png Ϗϡʔͷ͖߹Θͤࠩ failed_*.png ݱࡏͷϏϡʔ
reference_*.png ࢀর༻ͷϏϡʔ(͋Δ͖Ϗϡʔͷը૾)
FailureDiffsͷத
ࢀর༻ͷը૾ͷ࠶ੜ ઌ΄ͲͷςετϏϡʔʹ͕ࠩ͋Γςετࣦഊ͠·ͨ͠ ͕ɺఆͨ͠௨Γͳ༁Ͱ͔͢Βɺ࠶ࢀর༻ͷը૾Λొ͠ ͠·͢ɻ
جຊతͳ͍ํ(·ͱΊ) ͜ͷΑ͏ͳ࡞ۀΛ܁Γฦ͢ࣄͰҎԼͷΑ͏ͳԸܙΛड͚Δ͜ͱ ͕Ͱ͖·͢ɻ • ҙਤ͠ͳ͍ը໘่ΕΛݕग़དྷΔ • PR࣌ʹϦϑΝϨϯεը૾ؚ͕·ΕΔࣄͰը໘ͷ֬ೝָ͕ʹͳ Δ
Tips
ෳαΠζͷରԠ ϏϡʔͷαΠζॎԣͷରԠͳͲͨ͘͠ͳΓ·͢ΑͶʁ ྫ͑ྻڍܕͰσόΠεαΠζΛఆٛ enum DeviceSize: String { case size_10_5_inch =
"10.5inch" case size_12_9_inch = "12.9inch" static func all() -> [DeviceSize] { return [ .size_10_5_inch, .size_12_9_inch, ] }
ෳαΠζͷରԠ ͖ຖͷ֤σόΠεͷαΠζ(Rect)Λฦ͢ϝιουΛੜͨ͠Γ ͢ΔͱָʹͳΓͦ͏Ͱ͢ɻ func frame(with orientation: UIInterfaceOrientation) -> CGRect {
switch (self, orientation) { case (.size_10_5_inch, .portrait): return CGRect(x: 0, y: 0, width: 834, height: 1112) case (.size_10_5_inch, .landscapeLeft): return CGRect(x: 0, y: 0, width: 1112, height: 834) case (.size_12_9_inch, .portrait): return CGRect(x: 0, y: 0, width: 1024, height: 1366) case (.size_12_9_inch, .landscapeLeft): return CGRect(x: 0, y: 0, width: 1366, height: 1024) default: return CGRect.zero } } }
ෳαΠζͷରԠ FBSnapshotVerifyViewجຊతʹ1ϏϡʔͣͭVerify͍ͯ͘͠ͷ Ͱ͕͢ɺSnapshotVerifyViewAllSizeΛ࡞ͬͯෳαΠζΛҰ ؾʹςετग़དྷΔΑ͏ʹͨ͠Γ͍ͯ͠·͢ɻ extension FBSnapshotTestCase { public func SnapshotVerifyViewAllSize(_
vc: UIViewController, identifier: String = "", orientation: UIInterfaceOrientation) { for size in DeviceSize.all() { XCTContext.runActivity(named: "\(identifier)_\(size.rawValue)", block: { activity in let view = vc.view! view.frame = size.frame(with: orientation) FBSnapshotVerifyView(view, identifier: activity.name) }) } } }
Ϗϡʔͷঢ়ଶ࡞Γʹ͍ͭͯ • XCUIDevice.shared.orientationΛsetupͰ੍ޚग़དྷΔʁ • ࣦഊ͢Δ͜ͱ͕͋ͬͨ(or ग़དྷͳ͔ͬͨ) هԱʹͳ ͍ •
࣮ߦΓ͘ͳͬͨ • UIςετͷΈΛ͏ࣄʹҧײΛײͨ͡ • ૉʹΠχγϟϥΠβͰDI͢Δࣄʹͨ͠
ɹϨϏϡʔ࣌ʹཱͭ GithubGitlabը૾ࠩΛදࣔͰ͖ΔΑ͏ʹͳͬͨͷͰϨ Ϗϡʔ࣌ʹԿ͕มΘ͔ͬͨΛ֬ೝ͍͢͠
ݒ೦ • ը໘͕ଟ͍ΞϓϦͷ߹ͷϦϙδτϦͷαΠζ૿Ճ • Uber͕ϝϯςΊΔ • ࠓࣗͰר͖औͬͯϝϯς͢Δؾ࣋ͪΛ࣋ͱ͏͔ͳ ͱɻ
·ͱΊ • UIςετE2EͰͳ͘ϏϡʔͷΈΛςετ͍ͨ͠߹ʹ͓ ͢͢ΊͰ͢ • ௨ৗͷ୯ମςετΑΓ͔͔࣌ؒΓ·͢ • ϏϡʔͷϓϩύςΟͳͲʹΞΫηεͯ͠ςετ͢Δํ๏ ͋Δ
Ҏ্ɺ͝੩ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ɻ
ࢀߟ https://github.com/facebookarchive/ios-snapshot-test-case https://github.com/facebookarchive/ios-snapshot-test-case/ issues/227#issuecomment-335175385 https://www.objc.io/issues/15-testing/snapshot-testing/