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
88
iOSアプリ開発を始めよう
tamaki
0
130
詳解xcresult.pdf
tamaki
0
310
メルペイでのリグレッションテスト自動化推進のこれまでとこれから
tamaki
0
690
What do you want to test with UI Test v2
tamaki
2
850
JPQRによって変わる日本のQRコード決済
tamaki
0
250
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.6k
Other Decks in Technology
See All in Technology
Postman と API セキュリティ / Postman and API Security
yokawasa
0
200
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
2
360
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
340
生成AIのガバナンスの全体像と現実解
fnifni
1
190
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
460
WACATE2024冬セッション資料(ユーザビリティ)
scarletplover
0
200
大幅アップデートされたRagas v0.2をキャッチアップ
os1ma
2
540
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.3k
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
190
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
150
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
110
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
51
7.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Music & Morning Musume
bryan
46
6.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Building Applications with DynamoDB
mza
91
6.1k
Code Review Best Practice
trishagee
65
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Six Lessons from altMBA
skipperchong
27
3.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Gamification - CAS2011
davidbonilla
80
5.1k
A Tale of Four Properties
chriscoyier
157
23k
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/